使用extjs4与c#我如何访问我的数据
本文关键字:访问 我的 数据 何访问 extjs4 使用 | 更新日期: 2023-09-27 18:06:34
我需要通过表单将用户数据添加到我的数据库
所以我有一个表单,它的提交处理程序是这样的xtype: 'fieldset',
title: 'User information',
defaults: {
//width: 230,
labelStyle: 'font-size:10px',
labelWidth: 105
},
defaultType: 'textfield',
layout : 'anchor',
items: [{
fieldLabel: 'Name',
anchor: '98%',
allowBlank: false,
name: 'company'
}, {
fieldLabel: 'Last Name',
anchor: '98%',
name: 'price'
}, {
fieldLabel: 'Email ',
anchor: '98%',
allowBlank: false,
vtype: 'email',
name: 'pctChange'
}
]
},
{ border: false,
buttons: [{
text: 'Update user',
handler: function () {
{
if (this.up('form').getForm().isValid())
{
this.up('form').getForm().submit({url : 'save.cs' }); // this would submit the form to the configured url
//this.up('form').getForm().reset();
Ext.MessageBox.show({
title: 'Success !',
msg: 'Changes saved successfully<br />',
icon: Ext.MessageBox.INFO
})
}
从我的理解,提交函数调用一个脚本(在我的情况下save.ashx),应该更新我的数据库!
我有两个问题:
1-我如何访问我的数据(在表单中提交)我试图在保存函数中添加参数,您将在下面看到,但我不确定这个
2-i得到一个内部服务器错误时,保存。ashx被称为
下面是我的脚本: public class save
{
SqlConnection dbConn = new SqlConnection("............");
public void saveUser(string firstname,string lastname,string email)
{
try
{
string str = "insert into UTILISATEUR (firstname, lastname, email ) values ( '""+firstname+"'" , '""+lastname+"'" , '""+email+"'" )";
SqlCommand sqlCommand = new SqlCommand(str);
sqlCommand.Connection = dbConn;
sqlCommand.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(sqlCommand);
dbConn.Open();
if (sqlCommand.Connection.State == ConnectionState.Open)
{
sqlCommand.ExecuteNonQuery();
dbConn.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
}
感谢您的宝贵时间
.cs-files被IIS禁止-这些是c#源代码,不应该被最终用户访问。最终用户应该以这种或另一种方式访问这些源的编译版本。例如,你可以创建HTTP处理程序(.ashx-file)来处理你的请求。
这是行不通的,因为Li0liQ说你不能执行。cs文件。
c#是一种编译语言,而不是像PHP那样的"脚本语言"。
我认为你应该读一本关于如何用c#开发web应用程序的书。
此外,你在saveUser中的代码永远不会工作,因为
dbConn.Open();
if (sqlCommand.Connection.State == ConnectionState.Open)
{
dbConn.Close();
}
sqlCommand.ExecuteNonQuery();
打开连接,然后检查状态,如果打开,关闭连接,然后执行命令。
这没有意义。
dbConn.Open();
sqlCommand.ExecuteNonQuery();
dbConn.Close();