我只想返回 messageID 但它不能正常工作。如何返回单个字符串值?
[WebMethod]
public string messageComeGetID(string from, string to)
{
try
{
sqlConn.Open();
}
catch (Exception e)
{
return null;
}
// select messageID from tblMessage where [from] = '2' AND [to] = '4' gibi.
SqlCommand cmd3 = new SqlCommand("select messageID from tblMessage where [from]=@from AND [to]=@to", sqlConn);
cmd3.Parameters.AddWithValue("@from", from);
cmd3.Parameters.AddWithValue("@to", to);
cmd3.Connection = sqlConn;
object value = cmd3.ExecuteScalar();
string messageID = Convert.ToString(value);
cmd3.ExecuteNonQuery();
cmd3.Dispose();
sqlConn.Close();
return messageID;
}