为什么不可用的总是回来
本文关键字:回来 为什么不 | 更新日期: 2023-09-27 18:19:02
我一定是错过了一些非常简单的东西,但为什么"不可用"总是返回?我也试过如何从数据表中获取特定的列值?西雅图莱昂纳德,但仍然没有运气。
int ID;
string sQuery = "INSERT INTO dbo.tbl_personDetails " +
"(" +
"EmployeeID " +
",Title " +
",Name " +
")" +
"VALUES" +
"(" +
"@EmployeeID " +
",@Title " +
",@Name " +
") " ;
SqlCommand comm = new SqlCommand(sQuery);
comm.Parameters.Add(new SqlParameter("@EmployeeID", ToolTip.getUserName(GetUser.GetNtLoginID())));
comm.Parameters.Add(new SqlParameter("@Title", ddlTitle2.Text.ToString()));
comm.Parameters.Add(new SqlParameter("@Name", Name.Text.ToString()));
ID = DBConnect.InsertRecordGetID(comm, sQuery);
if (ID > 0)
{
//complete the Reference Number
string divCode;
string sSql =
"SELECT TheDivision FROM dbo.tbl_Incident_Details WHERE ID = " + ID;
DataTable dt = new DataTable();
dt = DBConnect.DataReaderDataTable(sSql);
if(dt.Rows.Count > 0)
{
divCode = dt.Rows[0][0].ToString();
}
else
{
divCode = "Unavailable";
}
string TheDate = DateTime.Now.Year.ToString();
string TheYear = TheDate.Substring(2, 2);
string RefNo = "FAI/" + ID + "/" + divCode + "/" + TheYear;
string sSqlRefNo = "UPDATE dbo.tbl_personDetails " +
"SET " +
"RefNo = '" + RefNo + "' " +
"WHERE " +
"ID = @ID";
SqlCommand commRefNo = new SqlCommand(sSqlRefNo);
commRefNo.Parameters.Add(new SqlParameter("@RefNo", RefNo));
commRefNo.Parameters.Add(new SqlParameter("@ID", ID));
if (DBConnect.CmdExecute(commRefNo, sSqlRefNo))
{
Response.Redirect("~/FileUpload.aspx?id=" + ID);
}
else
{
}
}
else { }
}
}
任何建议吗?
编辑:我现在已经发布了完整的功能。也不是divCode是数据库中的varchar而不是int。dt{}{System.ComponentModel基地。MarshalByValueComponent}: {}CaseSensitive:假ChildRelations: {System.Data.DataRelationCollection.DataTableRelationCollection}列:{System.Data.DataColumnCollection}约束:{System.Data.ConstraintCollection}数据集:零DefaultView: {System.Data.DataView}DisplayExpression:"ExtendedProperties: Count = 0HasErrors:假IsInitialized:真地区:{en -}MinimumCapacity: 50名称空间:"ParentRelations: {System.Data.DataRelationCollection.DataTableRelationCollection}前缀:"PrimaryKey: {System.Data.DataColumn [0]}RemotingFormat: Xml行:{System.Data.DataRowCollection}网站:零表名:"
我不知道这是多少答案,但它解决了它!我不知道周五下午我在想什么,但是这个该死的逻辑并不好,因为我试图在输入数据之前提取数据,这是可能的,因为除法确实存在,但是当我已经在前端有了另一个用户选择除法的部分时,这有什么意义呢,所以没有现实世界的实用性!所以说得够多了,但是这个为我做了:
//Store what is selected from the Division's ddl
string areaSelected = ddlArea.Text.ToString();
//Then
ID = DBConnect.InsertRecordGetID(comm, sQuery);
if (ID > 0)
{
//complete the Reference Number
//string divCode;
//string sSql =
//"SELECT TheDivision FROM dbo.tbl_Incident_Details //WHERE ID = " + ID;
//DataTable dt = new DataTable();
//dt = DBConnect.DataReaderDataTable(sSql);
//if(dt.Rows.Count > 0)
//{
// divCode = dt.Rows[0][0].ToString();
//}
//else
//{
// divCode = "Unavailable";
//}
string TheDate = DateTime.Now.Year.ToString();
string TheYear = TheDate.Substring(2, 2);
string RefNo = "FAI/" + ID + "/" + areaSelected + "/" + TheYear;
//The Update and the rest then works neatly and I get a nicely formated string in my db ;-)