我需要返回插入记录的值以传递给打开表单的代码。我如何得到这个价值?下面的代码添加一条记录并刷新一个datagridview。插入行的返回值
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("Data Source=***.**.***.**,****;Initial Catalog=newCityCollection_Aracor;Persist Security Info=True;User ID=4456r;Password=654935749653");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT PropertyInformation (ClientKey) VALUES (1)";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
this.propertyInformationDataGridView.Invalidate();
this.propertyInformationDataGridView.EndEdit();
this.propertyInformationDataGridView.Refresh();
this.newCityCollectionDataSet.AcceptChanges();
this.propertyInformationTableAdapter.Fill(newCityCollectionDataSet.PropertyInformation);
这是一个有点难以理解。我能获得更多的上下文吗? – phadaphunk
你在说什么“价值”? –
我正在使用窗体上的Datagridview作为案例管理工具来选择记录。我希望能够添加记录并立即打开表单。我知道如何打开表格以及什么但不知道如何检索新创建的记录的PK。所以点击按钮,创建记录,检索PK,然后打开记录在表单中是我的目的。 – korrowan