我需要返回插入記錄的值以傳遞給打開表單的代碼。我如何得到這個價值?下面的代碼添加一條記錄並刷新一個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