Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
- {
- string db2 = Text1;
- string user2 = Text2;
- string pass2 = Text3;
- string selected = this.ComboBox1.GetItemText(this.ComboBox1.SelectedItem);
- using (SqlConnection SqlConn = new SqlConnection(@"Data Source=server;Initial Catalog =" + db2 + "; User ID =" + user2 + "; Password =" + pass2 + ""))
- {
- SqlConn.Open();
- SqlCommand SqlCmd2 = new SqlCommand();
- SqlCommand SqlCmd3 = new SqlCommand();
- SqlCmd2.Connection = SqlConn;
- SqlCmd3.Connection = SqlConn;
- SqlCmd2.CommandText = "SELECT isnull(has_perms_by_name('" + db2 + ".dbo." + selected + "', 'OBJECT', 'INSERT'), 0)";
- SqlCmd3.CommandText = "SELECT isnull(has_perms_by_name('" + db2 + ".dbo." + selected + "', 'OBJECT', 'UPDATE'), 0)";
- Int32 number2 = (Int32)SqlCmd2.ExecuteScalar();
- Int32 number3 = (Int32)SqlCmd3.ExecuteScalar();
- if (number2 == 1)
- {
- if (!dataGridView1.Rows[e.RowIndex].IsNewRow)
- {
- if (e.RowIndex < dataGridView1.NewRowIndex)
- {
- if (AddedRowIndex != e.RowIndex)
- {
- MessageBox.Show("Not allowed to edit previous records!");
- e.Cancel = true;
- }
- }
- }
- }
- else if ((number2 == 1) && (number3 == 1))
- {
- //enable editing of all records in table
- }
- SqlConn.Close();
- }
- }
Add Comment
Please, Sign In to add comment