Guest User

Untitled

a guest
Dec 14th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  2. {
  3. string db2 = Text1;
  4. string user2 = Text2;
  5. string pass2 = Text3;
  6. string selected = this.ComboBox1.GetItemText(this.ComboBox1.SelectedItem);
  7. using (SqlConnection SqlConn = new SqlConnection(@"Data Source=server;Initial Catalog =" + db2 + "; User ID =" + user2 + "; Password =" + pass2 + ""))
  8. {
  9. SqlConn.Open();
  10. SqlCommand SqlCmd2 = new SqlCommand();
  11. SqlCommand SqlCmd3 = new SqlCommand();
  12. SqlCmd2.Connection = SqlConn;
  13. SqlCmd3.Connection = SqlConn;
  14. SqlCmd2.CommandText = "SELECT isnull(has_perms_by_name('" + db2 + ".dbo." + selected + "', 'OBJECT', 'INSERT'), 0)";
  15. SqlCmd3.CommandText = "SELECT isnull(has_perms_by_name('" + db2 + ".dbo." + selected + "', 'OBJECT', 'UPDATE'), 0)";
  16. Int32 number2 = (Int32)SqlCmd2.ExecuteScalar();
  17. Int32 number3 = (Int32)SqlCmd3.ExecuteScalar();
  18. if (number2 == 1)
  19. {
  20. if (!dataGridView1.Rows[e.RowIndex].IsNewRow)
  21. {
  22. if (e.RowIndex < dataGridView1.NewRowIndex)
  23. {
  24. if (AddedRowIndex != e.RowIndex)
  25. {
  26. MessageBox.Show("Not allowed to edit previous records!");
  27. e.Cancel = true;
  28. }
  29. }
  30. }
  31. }
  32. else if ((number2 == 1) && (number3 == 1))
  33. {
  34. //enable editing of all records in table
  35. }
  36. SqlConn.Close();
  37. }
  38. }
Add Comment
Please, Sign In to add comment