Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my coding that I am using to update a row of data on the datagrid and to save that data to sql. Yesterday this coding worked but now im getting this error and I dont know what is wrong.
C#
try
            {

                SqlCommandBuilder local_SqlCommandBuilder = new SqlCommandBuilder(da);

                local_SqlCommandBuilder.ConflictOption = System.Data.ConflictOption.OverwriteChanges;

                da.UpdateCommand = local_SqlCommandBuilder.GetUpdateCommand();

                DataView dv = DGAdmin.ItemsSource as DataView;
                DataTable dtn = dv.Table;
                
                da.Update(dtn);

                dt.AcceptChanges();

            }
            catch (Exception)
            {

                throw;
            }

The Error that I am getting is: The DataAdapter.SelectCommand property needs to be initialized.
Posted
Updated 13-Nov-14 19:46pm
v2
Comments
DamithSL 14-Nov-14 1:49am    
how you create da? is there primary key to your table?
RenaldoGG 14-Nov-14 2:02am    
Sorry I am still new to this, the GetSelectCommand(); shows an error does not contain definition. I have checked my using directives, is it wpf code or windows forms?
DamithSL 14-Nov-14 2:14am    
how you create data adapter? you need to give select command as parameter
/\jmot 14-Nov-14 2:14am    
i think..
SqlDataAdapter da=new SqlDataAdapter(sqlCommand);
Jineesh TR 14-Nov-14 2:48am    
You may need to provide command, command type, connection etc for a dataadapter. Did you do that?

1 solution

Dear RenaldoGG,

What you provide is I think only an update method, where is the Method to collect / get data from Database. You need a method for collecting data and Select command for the DA is located in that. Please check it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900