我正在尝试从SQL表中设置日历的选定日期。只需将表格中的日期显示在日历上。我的问题在最后一行。
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Calendar2.SelectedDate = DateTime.Now;
SVCID = (string)(Session["SVCID"]);
CustID = (string)(Session["CUSTID"]);
int SVC_ID = System.Convert.ToInt32(SVCID);
int Cust_ID = System.Convert.ToInt32(CustID);
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["lg_db"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Select * From Customers where Cust_ID = @CID", con))
{
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@CID", CustID);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
TB_Cname.Text = dt.Rows[0]["Cust_Name"].ToString();
TB_Cphone.Text = dt.Rows[0]["Cust_phone"].ToString();
TB_Cmobile.Text = dt.Rows[0]["Cust_Mobile"].ToString();
TB_Cadd.Text = dt.Rows[0]["Cust_Add"].ToString();
DDL_PType.DataTextField = dt.Rows[0]["Cust_City"].ToString();
DDL_City.DataTextField = dt.Rows[0]["Cust_City"].ToString();
con.Close();
}
using (SqlCommand cmd2 = new SqlCommand("Select * From SVC where SVC_ID = @SID", con))
{
SqlDataAdapter sqlDa2 = new SqlDataAdapter(cmd);
cmd2.Parameters.AddWithValue("@SID", SVC_ID);
sqlDa2.Fill(dt);
if (dt.Rows.Count > 0)
{
DDL_PType.DataTextField = dt.Rows[0]["Product_type_ID"].ToString();
DDL_Model.DataTextField = dt.Rows[0]["Product_ID"].ToString();
TB_serial.Text = dt.Rows[0]["SerialNumber"].ToString();
TB_Symptom.Text = dt.Rows[0]["Symptom"].ToString();
Calendar2.SelectedDate = dt.Rows[0]["Symptom"].ToString();
}
}
}
}
}
}
此代码显示错误:
“无法将Type字符串转换为datetime”
谢谢
答案 0 :(得分:0)
试试这个
-(void)GetPostPreperation :(NSMutableURLRequest *)request isGet:(BOOL)isGet jsonBody:(NSMutableDictionary *)jsonBody block:(myCompletion)string
{
string(@"yes");
}
我想你在这里使用了错误的字段,这是一个错字:
Calendar2.SelectedDate = DateTime.Parse(dt.Rows[0]["Symptom"].ToString());
我认为不是您要设置dt.Rows[0]["Symptom"].ToString()
的{{1}}字段。
答案 1 :(得分:0)
使用Calendar2.SelectedDate = DateTime.Now.ToString();