-1

I need to add user data to my database via a form

So I have a form with a submit handler like this :

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
                                                    })                              
                             }

from what i understood,the submit function call a script (in my case save.ashx) that should update my database!

I have two issues :

1-how do I access my data (submited in the form) I tried to add arguments in the save function as you will see below but im not quit sure about this

2-i get an internal server error when the save.ashx is called

Here is my script:

 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;
         }
    }
}

thanks for ur time

Armance
  • 5,350
  • 14
  • 57
  • 80

2 Answers2

1

.cs-files are forbidden by IIS - those are C# sources and should not be accessed by end users. End users should this way or another access compiled versions of those sources. E.g. you could create HTTP Handler(.ashx-file) that will handle your requests.

This question will help you get the basics about submitting form to HTTP Handler.

Community
  • 1
  • 1
Li0liQ
  • 11,158
  • 35
  • 52
  • thanks..i did reate an .ashx file but then i get an internal server error – Armance Aug 25 '11 at 14:15
  • I suppose it makes sense trying to develop everything incrementally, step by step. First - working http handler(default studios template should work), second - trying to submit the form and get its values on server end (in debugger), third - trying to pass those values to database. – Li0liQ Aug 25 '11 at 14:20
1

That will never work bebcause as Li0liQ said you can't execute a .cs file.

C# is a compiled language, thats not a "scripting language" such as PHP.

I think you should read a book about how develop web applications in C#.

And furthermore, your code in saveUser will never work because

 dbConn.Open();

  if (sqlCommand.Connection.State == ConnectionState.Open)
  {
      dbConn.Close();
  }
  sqlCommand.ExecuteNonQuery();

You open the connection, then you check the state, and if it is opened, you close it, then you execute your command.

That does not make sense.

  dbConn.Open();

  sqlCommand.ExecuteNonQuery();

  dbConn.Close();

This way it would make more sense.

Charles Ouellet
  • 6,338
  • 3
  • 41
  • 57
  • thanks. i changed it,and updated my question according to both ur answers. i am trying to learn c# as i go because i have ver tight deadlines,thank you for ur patience – Armance Aug 25 '11 at 14:21