【发布时间】:2011-08-25 14:07:53
【问题描述】:
我需要通过表单将用户数据添加到我的数据库中
所以我有一个带有这样的提交处理程序的表单:
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-调用 save.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;
}
}
}
感谢您的宝贵时间
【问题讨论】: