我在表单加载中有此代码,用于在我的数据表中填充我的数据,然后填充到我的 SearchLookupEdit 中:
FillGrids(oData, "POLIST",
"SELECT [PORecord].[POID],[ItemCode],[PONumber],"
+ "[SiteNo]+' '+[Place]+' '+[Name]+' '+[ScopeOfWork]"
+ "+' '+CAST([DeliveryDate] AS VARCHAR(30))"
+ "+' '+CAST([PRNumber]AS VARCHAR(10))+' '+[Requisitioner] AS Name,"
+ "[UnitPrice],[Quantity],[Unit],Completed,Status"
+ " FROM [Globaltek-Final].[Project].[PORecord]"
+ " INNER JOIN Project.POStatus ON Project.PORecord.POID = Project.POStatus.POID",
CommandType.Text);
cmbPOID.Properties.DataSource = oData.Tables["POLIST"];
cmbPOID.Properties.DisplayMember = "PONumber";
cmbPOID.Properties.ValueMember = "POID";
然后通过这个事件:
private void cmbPOID_EditValueChanged(object sender, EventArgs e)
{
//cmbPOID.ShowPopup();
System.Data.DataRow row = gvPOID.GetDataRow(gvPOID.FocusedRowHandle);
try
{
oPOID = row[0].ToString();
txtAmount.Text = row["UnitPrice"].ToString();
}
catch (NullReferenceException ex)
{
MessageBox.Show(ex.Message);
}
}
我可以更改控件的值,然后将其添加到我的数据库中。
编辑:要加载我存储在数据库中的数据,我使用以下代码:
using (SqlCommand xComm = new SqlCommand())
{
xComm.Connection = xConn;
xComm.CommandText =
"SELECT [ProjectID] ,[Year] ,[NTPID] ,Project.MainProjectRecord.[POID],"
+ "[SiteID] ,[SiteName] ,[SiteDetailsID] ,[EquipmentID] ,[RepGlobaltekID],"
+ "[CompletedID] ,[OnGoingID] ,Project.PORecord.POID"
+ " FROM [Globaltek-Final].[Project].[MainProjectRecord]"
+ " INNER JOIN Project.PORecord ON Project.MainProjectRecord.POID = Project.PORecord.POID"
+ " WHERE ProjectID = @recordID";
xComm.CommandType = CommandType.Text;
xComm.Parameters.AddWithValue("@recordID", RecordID);
SqlDataReader xReader = null;
try
{
xConn.Open();
xReader = xComm.ExecuteReader();
while (xReader.Read())
{
txtSiteID.Text = xReader["SiteID"].ToString();
txtSiteName.Text = xReader["SiteName"].ToString();
cmbPOID.EditValue = xReader["POID"].ToString();
cmbPOID.Properties.GetDisplayTextByKeyValue(xReader["POID"].ToString());
//cmbPOID.EditValue = xReader["POID"].ToString();
}
xReader.Close();
}
.....
我的问题是如何设置或加载从数据库中返回到 SearchLookupEdit 控件的值?