SqlConnection conn = new SqlConnection(connstring);
conn.Open();
try
{
string sqlstr = "select * from K_LF where lf_bm='" + BM + "' and LF_DM='" + JJDM + "' AND LF_RQ LIKE '" + RQ + "%'";
SqlCommand CMDselect = new SqlCommand(sqlstr, conn);
SqlDataReader RA = CMDselect.ExecuteReader();
string updatestr = "";
if (RA.Read())
updatestr = "update K_LF set lf_rq='" + RQ + "' where lf_bm='" + BM + "' and LF_DM='" + JJDM + "'";
else
updatestr = "insert into K_LF values ('" + BM + "','" + JJDM + "','" + JJMC + "','" + RQ + "')";
SqlCommand CMD = new SqlCommand(updatestr, conn);
CMD.ExecuteNonQuery(); return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
conn.Open();
try
{
string sqlstr = "select * from K_LF where lf_bm='" + BM + "' and LF_DM='" + JJDM + "' AND LF_RQ LIKE '" + RQ + "%'";
SqlCommand CMDselect = new SqlCommand(sqlstr, conn);
SqlDataReader RA = CMDselect.ExecuteReader();
string updatestr = "";
if (RA.Read())
updatestr = "update K_LF set lf_rq='" + RQ + "' where lf_bm='" + BM + "' and LF_DM='" + JJDM + "'";
else
updatestr = "insert into K_LF values ('" + BM + "','" + JJDM + "','" + JJMC + "','" + RQ + "')";
SqlCommand CMD = new SqlCommand(updatestr, conn);
CMD.ExecuteNonQuery(); return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
CMD.ExecuteNonQuery();
到這裡應該是要更新或插入到數據庫,但在數據庫的數據沒有變化
斷點調試了,執行是沒有問題,語法也沒問題。就是沒有更改數據庫。
conn.Open();
樓主的不報錯
估計是到上面這兩行代碼就報錯了
RA.Close()了也不行。
[WebMethod
public bool saveHJ(string BM, string RQ, string JJDM, string JJMC)
{
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
try
{
string sqlstr = "select * from K_LF where lf_bm='" + BM + "' and LF_DM='" + JJDM + "' AND LF_RQ LIKE '" + RQ + "%'";
SqlCommand CMDselect = new SqlCommand(sqlstr, conn);
SqlDataReader RA = CMDselect.ExecuteReader();
string updatestr = "";
if (RA.Read())
updatestr = "update K_LF set lf_rq='" + RQ + "' where lf_bm='" + BM + "' and LF_DM='" + JJDM + "'";
else
updatestr = "insert into K_LF values ('" + BM + "','" + JJDM + "','" + JJMC + "','" + RQ + "')";
SqlCommand CMD = new SqlCommand(updatestr, conn);
CMD.ExecuteNonQuery();
RA.Close();
return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
}
{
...
}
[WebMethod
public bool saveHJ(string BM, string RQ, string JJDM, string JJMC)
{
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
try
{
string sqlstr = "select * from K_LF where lf_bm='" + BM + "' and LF_DM='" + JJDM + "' AND LF_RQ LIKE '" + RQ + "%'";
SqlCommand CMDselect = new SqlCommand(sqlstr, conn);
SqlDataReader RA = CMDselect.ExecuteReader();
string updatestr = "";
if (RA.Read())
updatestr = "update K_LF set lf_rq='" + RQ + "' where lf_bm='" + BM + "' and LF_DM='" + JJDM + "'";
else
updatestr = "insert into K_LF values ('" + BM + "','" + JJDM + "','" + JJMC + "','" + RQ + "')";
RA.Close();
SqlCommand CMD = new SqlCommand(updatestr, conn);
CMD.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
}