Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Hello didiermook could u help me pls!!

sayyed_asayyed_a Posts: 13Member
[b][red]This message was edited by sayyed_a at 2003-10-27 11:38:41[/red][/b][hr]
Hi i am a newbie. I have a webform which has several textboxes and a datagrid.I have binded the detail table with the datagrid.The textboxes are bound to the header table. What i want to do is that when i click on save button both the contents of the datagrid(i.e. detail table) and the textboxes(i.e. the header table) should be updated.
can anybody help me pls.

Ok to tell u more what i want i am doing is that i want to update the detail table and the header table, once i click on the save button.
I hope i have made the problem clearly understood.
Thanks ina dvance


Comments

  • didiermookdidiermook Posts: 14Member
    Hi, Excuse me for the late answer I've been so busy these days.

    Well, This is how you can solve your problem:
    - The DataGrid is to be bound to a DataSet which has all details for the specific record, example :

    public void FillDataSet()
    {
    string sql = "select * from tableDetail where keyNo = " + keyNo;
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataGrid1.DataSource = ds;
    DataGrid1.DataBind();
    }
    //It's Just an example!
    This method is called when the page is loaded

    - When you save Data from the TextBoxes with the Button Saves. You Updates the DataBase or the DataSet. To See the changes mades in your DataBase or DataSet, you've to call again the method above, to refresh(if I can say that) the DataGrid, then you've all the record in the DataGrid actualized. The same is valide when you insert a record from your textboxes.

    P.S. The Textboxes are updated also using the DataBind() method of the Page!

    I hope it helps you!

    Thanks!

    mOoK!


    : [b][red]This message was edited by sayyed_a at 2003-10-27 11:38:41[/red][/b][hr]
    : Hi i am a newbie. I have a webform which has several textboxes and a datagrid.I have binded the detail table with the datagrid.The textboxes are bound to the header table. What i want to do is that when i click on save button both the contents of the datagrid(i.e. detail table) and the textboxes(i.e. the header table) should be updated.
    : can anybody help me pls.
    :
    : Ok to tell u more what i want i am doing is that i want to update the detail table and the header table, once i click on the save button.
    : I hope i have made the problem clearly understood.
    : Thanks ina dvance
    :
    :
    :

  • sayyed_asayyed_a Posts: 13Member
    Dear mOoK!
    Thanks for the reply but i think i did not write the question properly.What u have suggested is for the datagrid.This is the exact way that i have done as far as the datagrid is concerned and the datagrid is working fine, i mean its updating and saving the changes made to it.But what i want to do is whenever the user enters data into the text boxes and clicks on the save button. The data should be updated in the database table(SQL Server Table).The textboxes are nothing but the column names of a table.
    I hope i have made it clear
    your help will be highly appeciated

    sayyed




    Hi, Excuse me for the late answer I've been so busy these days.

    Well, This is how you can solve your problem:
    - The DataGrid is to be bound to a DataSet which has all details for the specific record, example :

    public void FillDataSet()
    {
    string sql = "select * from tableDetail where keyNo = " + keyNo;
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataGrid1.DataSource = ds;
    DataGrid1.DataBind();
    }
    //It's Just an example!
    This method is called when the page is loaded

    - When you save Data from the TextBoxes with the Button Saves. You Updates the DataBase or the DataSet. To See the changes mades in your DataBase or DataSet, you've to call again the method above, to refresh(if I can say that) the DataGrid, then you've all the record in the DataGrid actualized. The same is valide when you insert a record from your textboxes.

    P.S. The Textboxes are updated also using the DataBind() method of the Page!

    I hope it helps you!

    Thanks!

    mOoK!


    [b][red]This message was edited by sayyed_a at 2003-10-27 11:38:41/red][/b][hr]
    Hi i am a newbie. I have a webform which has several textboxes and a datagrid.I have binded the detail table with the datagrid.The textboxes are bound to the header table. What i want to do is that when i click on save button both the contents of the datagrid(i.e. detail table) and the textboxes(i.e. the header table) should be updated.
    can anybody help me pls.

    Ok to tell u more what i want i am doing is that i want to update the detail table and the header table, once i click on the save button.
    I hope i have made the problem clearly understood.
    Thanks ina dvance






  • didiermookdidiermook Posts: 14Member
    Hi sayyed,

    Let me try again to help you, sorry for the first answer: Well, if I'm right you want to update a table using the Data from textboxes. No problem: There's two way to do it: with a stored procedure or directly with the code. this is how to do it with C# codes.

    - In your Button_Click method

    ...
    SqlConnection conn = new SqlConnection(connString);
    //The first step is to Create a Command
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = conn;
    // The CommandText is the sql string for your update
    // Note that the values to be passed are preceded with "@" for Sql
    // Server Databases.
    cmd.CommandText = "update tableName set Name = @name, Address = @address where keyCode = @keyCode";
    //Add the parameters to the cmd
    cmd.Parameters.Add("@name", SqlDbType.Char, 20);
    cmd.Parameters.Add("@address", SqlDbType.Char, 200);
    cmd.Parameters.Add("@keyCode", SqlDbType.Int, 0);
    //Set values to the Parameters
    cmd.Parameters["@name"].Value = TextBox1.Text;
    cmd.Parameters["@address"].Value = TextBox2.Text;
    cmd.Parameters["@keyCode"].Value = TextBox3.Text;
    //Execute the Update
    int rep = cmd.ExecuteNonQuery();

    If it's too difficult there's another way to make the sql string :
    ...
    string sql = "update tableName set Name = '" + TextBox1.Text +"', Address = '" + TextBox2.Text +"' where keyCode = "+ TextBox3.Text;
    SqlCommand cmd = new SqlCommand(sql, conn);
    int rep = cmd.ExecuteNonQuery();

    If I still did not answer your question, let me know I can still help you if possible. Keep on coding, it's good for your wealth!

    mOoK!

  • sayyed_asayyed_a Posts: 13Member
    Dear mOok,
    I actually did not read ur message properly and replied to u for the first time that ur code is for the datagrid. But now i hav etried the same code and although the problem is somewhat nearbe to be solved . I have one more thing to ask that is
    I have added the columns from the table that (these columns are assigned to the text boxes in the page).but in the original table there are some columns which i do not use presently in this screen.If i leave them it is showing error .So how can i sove this problem

    Thanks

  • didiermookdidiermook Posts: 14Member
    Hi,

    If you've have an error you'd better check in your table if the ohters fields(those who are not on your the Page) are ddefined to be "Not null" fields, 'coz if it's the case you'll always have a problem when your don't fill them. An other reason is you've bound your fields with staff like " />. You've to care that every textbox returns to the Database a correct format. If not, check also if every fields receive data in the correct format.

    Anyway, you can have more info of the error by catching an exception while inserting or updating:
    SqlCommand cmd = new SqlCommand("insert into ...", conn);
    try{
    string resp = cmd.ExecuteNonQuery();
    ...
    }
    catch (Exception exp)
    {
    string msg = exp.Message;
    //Display msg somewhere
    ...
    }

    Or use the Debugger. If you've a problem on it please send me the error message than I can see if I can help you more.

    Hope I help,

    mOoK!

    : Dear mOok,
    : I actually did not read ur message properly and replied to u for the first time that ur code is for the datagrid. But now i hav etried the same code and although the problem is somewhat nearbe to be solved . I have one more thing to ask that is
    : I have added the columns from the table that (these columns are assigned to the text boxes in the page).but in the original table there are some columns which i do not use presently in this screen.If i leave them it is showing error .So how can i sove this problem
    :
    : Thanks
    :
    :

Sign In or Register to comment.