KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am new to c# and try to bind a datagridview to a mssql database in visual studio 2010. The databindings are OK and everything seems to work. Except for a few strange errors: I get the error in the subject after: updating the same row 2 times, deleting a new inserted row, after updating a row when an other row was deleted (word changes to DeleteCommand) None of the solutions I found on Google workes for me. I hope someone can help me with this. Here is te code: private void fillDatagrid() { //fill datagrid ADO.NET conn = new SqlConnection(TestApp.Properties.Settings.Default.TestdatabaseConnectionString); cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "SelectFrom"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@table", SqlDbType.NVarChar, 50).Value = "Countries"; cmd.Parameters.Add("@filters", SqlDbType.NVarChar, 300).Value = ""; adapt = new SqlDataAdapter(cmd); dt = new DataTable(); adapt.Fill(dt); dt.TableName = "Countries"; conn.Close(); BindingSource src = new BindingSource(); src.DataSource = dt; dt.RowChanged += new DataRowChangeEventHandler(dt_RowChanged); dgDatabaseGrid.DataSource = src; dgDatabaseGrid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); //dgDatabaseGrid.RowValidating += new DataGridViewCellCancelEventHandler(dgDatabaseGrid_RowValidating); //disable columns: dgDatabaseGrid.Columns[0].Visible = false; dgDatabaseGrid.Columns["date_insert"].Visible = false; dgDatabaseGrid.Columns["user_insert"].Visible = false; dgDatabaseGrid.Columns["date_change"].Visible = false; dgDatabaseGrid.Columns["user_change"].Visible = false; dgDatabaseGrid.Columns["de
Tags (comma-separated)
Save Edits
Cancel