locked
updating data through Datagridview control RRS feed

  • Question

  • In my winform application I want to update data directly through datagridview control

    but that is not happening and there is no error also.Specially when only a single record is

    populated in datagridview control.No updates are happening.How to do it?

    Thanks in advance.

    Monday, April 30, 2012 5:38 AM

Answers

  • Hello,

    I have got the solution to my problem with smallmoney datatype.It works fine after I made changes in stored proc.

    Thanks

    • Marked as answer by Papy Normand Tuesday, September 11, 2012 9:29 AM
    Tuesday, September 11, 2012 6:29 AM

All replies

  • Hello,

    Please, could you provide the code you are using to update your database ? Could you explain how the code updating the database is executed ( thru a click on a button ? ) ?

    Are you using the DataSoource property of your DataGridView to bind your table and your DataGridView ?

    http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx

    You may also use a BindingSource also.

    Please, could you tell us the version and edition of your DBMS ? Is it a SQL Server ?

    Please, could you provide also your connection string ? ( i know that it is possible to have problems with a SQL Server Express Edition )

    We are waiting for your feedback to try to help you more efficiently.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Monday, April 30, 2012 8:17 AM
  • I am fetching data with the help of stored proc as per the parameter in my datagridview control.then I update data  in my datagridview control with the help of button event.

    but it does not get modify and throws tablemapping error.

    Code to fetch data on button click event :

    ConnectionStringSettings mycon = ConfigurationManager.ConnectionStrings["DataConnectionString1"];
                        conn = new SqlConnection(mycon.ConnectionString);
                        cmd = new SqlCommand();
                        cmd.Connection = conn;
                        cmd.Connection.Open();
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "dbo.[StdChequefeesPerExam]";

                        SqlParameter parastd = new SqlParameter();

                        parastd.ParameterName = "@Stdname";
                        parastd.Value = combxstdnames.SelectedValue.ToString();
                        cmd.Parameters.Add(parastd);

                        SqlParameter paraattempt = new SqlParameter();
                        paraattempt.ParameterName = "@attemptno";
                        paraattempt.Value = txtAttemptNum.Text;
                        cmd.Parameters.Add(paraattempt);

                        SqlParameter paraexam = new SqlParameter();
                        paraexam.ParameterName = "@examid";
                        paraexam.Value = comboxExamId.SelectedValue.ToString();
                        cmd.Parameters.Add(paraexam);



                        adap = new SqlDataAdapter();
                        adap.SelectCommand = cmd;
                        cmdbuilder = new SqlCommandBuilder(adap);
                        ds = new DataSet();
                        adap.Fill(ds, "ChequeRecptTbl");
                        RecptMasterGridvw.DataSource = ds;
                        RecptMasterGridvw.DataMember = "ChequeRecptTbl";
                        cmd.Connection.Close();

    Another button that modifies data of a datagridview.

    try
                {
                    cmdbuilder = new SqlCommandBuilder(adap);
                    ds = new DataSet();
                   //error Update unable to find TableMapping['ChequeRecptTbl'] or //DataTable'ChequeRecptTbl'.
                    adap.Update(ds, "ChequeRecptTbl");
                   
                    RecptMasterGridvw.Refresh();
                    UpdstatusLbl.Text = "Record Updated";
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }

    what is the problem?

    Thanks in advance.


    Thursday, May 3, 2012 9:18 AM
  • Hello,

    1st problem : you have forgotten to specify the size of the parameters

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx

    The definition of the table would be useful ( the full CREATE TABLE ).Idem the dbo.[StdChequefeesPerExam] stored procedure

    There is something i have not understood  "Another button that modifies data of a datagridview". Are you trying to update the contain of the datagridview or of the table(s) of your database ? I am sorry , it is not clear.

    If you have modified the contain of your datagridview and you want to update , delete or insert in the database, you have to use an AcceptChanges() method to validate your modifications.

    http://msdn.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx

    We are waiting for your feedback to try to help you more efficiently

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.


    • Edited by Papy Normand Wednesday, May 9, 2012 4:07 PM Added the link towards AcceptChanges and corrected AcceptChange to AcceptChanges
    Wednesday, May 9, 2012 4:04 PM
  • Hello,
    I am not able to update columns that are of smallmoney datatype through datagridview.what is the issue not getting.
    Tuesday, August 28, 2012 7:06 AM
  • Hello,

    I am glad to meet you nearly 3 months after the last post of this thread.

    Please, could you have a look at this link ?

    http://msdn.microsoft.com/en-us/library/cc716729(VS.90).aspx

    You have to "translate" the value of your "smallmoney" column of your datagridview from a string to a the Decimal .Net type.

    As we don't know what the full version/edition of your SQL Server ( and even whether you are using SQL Server ) , it is really difficult to help you more efficiently.

    It could be useful to know the structure of the table(s) and if you are using stored procedures to perform the SELECT/INSERT/UPDATE/DELETE queries

    We are waiting for your feedback to try to help you more efficiently.

    Have a nice day

    PS : Have you solved the question you are asked in your 1st post ? ( if yes, the solution would be appreciated as it could be useful for other potential posters having the same problems )


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Tuesday, August 28, 2012 11:43 AM
  • Hello srm 2010 ,

    Please, could you tell us whether you have succeeded to solve your problem.

    If yes, please , could you provide your solution as it would be useful for the people who could face the same problem ?

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Saturday, September 8, 2012 8:21 PM
  • Hello,

    I have got the solution to my problem with smallmoney datatype.It works fine after I made changes in stored proc.

    Thanks

    • Marked as answer by Papy Normand Tuesday, September 11, 2012 9:29 AM
    Tuesday, September 11, 2012 6:29 AM