im trying to add a new user to my database via a form
i prepared the form but my problem is how to save the data from this form to my database ?
im using c# and extjs4.0.1
i know i need to use submit on a button and give it an url
i did that but when i click on it nothing happens! no errors! i get the success info box! but when i check the database, there is nothing inserted!like my updateuser function have never been called?!!
here is my form script:
buttons: [{
text: 'Save user',
handler: function () {
if (this.up('form').getForm().isValid())
this.up('form').getForm().submit
({// this would submit the form to the configured url
url: 'update.ashx',
success: function (form, action) {
Ext.MessageBox.show({
title: 'Success !',
msg: 'Changes saved successfully<br />',
icon: Ext.MessageBox.INFO
})
},
});
this.up('form').getForm().reset();
}
and here is my update.ashx script:
public class update : IHttpHandler
{
SqlConnection dbConn = new SqlConnection("....");
public void ProcessRequest(HttpContext context)
{ }
public bool IsReusable
{
get { return false; }
}
public void updateUser(string firstname, string lastname, string email)
{
string str = "insert into User (Name , FName , 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();
}
}
}
do you have any idea please?
at least let me know if im on the right way or not…
thanks
first of all “success: function (form, action)” this function call doesn’t mean that the update user was a succes , just that the submit was successful .. for success you need to encode a json with success true, and then action.result.success will determine if success was true… check the api …..
Second, i’m not much of a c# guy … but it seems you don’t even process the request
Edit:
To avoid your duplicate problem send an extra param to the handler … and execute the update method only when receiving the update action in the request
the form submit sends the form values to the handler inside the HttpRequest object contained by the context object.. for retriving the form values you can check http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.processrequest.aspx example