主题:[讨论]c#写入SQL数据库总是出错,怎么也写不进去?请帮帮忙!
private void ensureButton3_Click(object sender, System.EventArgs e)
{
float price, time, reliability, availability;
price = float.Parse(expense.Text);
time = float.Parse(eTime.Text);
reliability = float.Parse(rValue.Text);
availability = float.Parse(aValue.Text);
try
{
string myConnectString = "Persist Security Info=False;Integrated Security=SSPI;database=zhwPaper;server=CLC-31071999FBB\\CLC;Connect Timeout=30";
SqlConnection myConn = new SqlConnection(myConnectString);
myConn.Open();
SqlCommand cmd =myConn.CreateCommand();
cmd.CommandText = "INSERT INTO wector_value(price, time, reliability, availability) VALUE('"+price+"', '"+time+"', '"+reliability+"', '"+availability+"')";
cmd.ExecuteNonQuery();
}
catch(Exception c)
{
Console.WriteLine("写入数据库错误:/n{0}", c.Message);
}
}
{
float price, time, reliability, availability;
price = float.Parse(expense.Text);
time = float.Parse(eTime.Text);
reliability = float.Parse(rValue.Text);
availability = float.Parse(aValue.Text);
try
{
string myConnectString = "Persist Security Info=False;Integrated Security=SSPI;database=zhwPaper;server=CLC-31071999FBB\\CLC;Connect Timeout=30";
SqlConnection myConn = new SqlConnection(myConnectString);
myConn.Open();
SqlCommand cmd =myConn.CreateCommand();
cmd.CommandText = "INSERT INTO wector_value(price, time, reliability, availability) VALUE('"+price+"', '"+time+"', '"+reliability+"', '"+availability+"')";
cmd.ExecuteNonQuery();
}
catch(Exception c)
{
Console.WriteLine("写入数据库错误:/n{0}", c.Message);
}
}