我在SQL Server中有一个float类型的列Probability
,而我在C#中有一些计算:
var _Total_Records = 0;
var _Matchings = 0;
var _Probability = 0.0;
_Matchings = Convert.ToInt32(_myCommand_2.ExecuteScalar());
_Probability = Convert.ToDouble(_Matchings.ToString()) / Convert.ToDouble(_Total_Records);
现在我想在_Probability
方法中将此WriteToDatabase()
值写入SQL Server表,即
public static void Write_To_Database(int _id, int _Matched, double _Prob)
{
var _Result = 0;
SqlConnection _con = _cs.GetConnection();
try
{
string _myUpdate_Command_1 = @"UPDATE AuthorCoAuthorProbability
SET Matched_Records = @_Matched_Records
Probability = @_Probability
WHERE id = @_id";
SqlCommand _myUpdate_Command = new SqlCommand(_myUpdate_Command_1, _con);
_myUpdate_Command.Parameters.AddWithValue("@_id", _id);
_myUpdate_Command.Parameters.AddWithValue("@_Matched_Records", _Matched);
_myUpdate_Command.Parameters.AddWithValue("@_Probability", _Prob);
_Result = _myUpdate_Command.ExecuteNonQuery();
_cs.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
在_Result =_myUpdate_Command.ExecuteNonQuery();
命令:
我得到了例外,即
Incorrect syntax near `Probability`
有没有数据类型错误?由于SQL Server表中的列数据类型为float
,并且我将double
的值_Probability
存储在其中,或者由于还有什么异常?
答案 0 :(得分:-2)
您的SQL语句中缺少逗号
替换
SET Matched_Records = @_Matched_Records Probability = @_Probability
与
SET Matched_Records = @_Matched_Records, Probability = @_Probability