QPixmap::save(QIODevice* device, const char* format, int quality)
答案 0 :(得分:4)
这里有一个缺失的撇号:
'"+textBox2 +"
但是不要使用字符串连接来构建查询,而是使用参数化查询。否则您将对SQL injection开放。
还可以使用using
语句来处置任何非托管资源/关闭连接。
using (var con = new SqlConnection("Data Source=SAGAR\\SQLEXPRESS;Initial Catalog=ClinicDb;Integrated Security=True"))
{
con.Open();
using (var sc = new SqlCommand("insert into Patient_Details values(@col1,@col2,@col3,@col4);", con))
{
sc.Parameters.Add("@Col1", SqlDbType.VarChar).Value = textBox1.Text;
sc.Parameters.Add("@Col2", SqlDbType.Int).Value = int.Parse(textBox2.Text);
// ..
int o = sc.ExecuteNonQuery();
// ...
}
}
首先使用正确的数据类型,我已经展示了varchar
和int
的示例。
答案 1 :(得分:0)
您在.Text
等结尾处遗漏了textBox1
并且您没有正确引用这些项目(您错过了很多'
)。变化:
SqlCommand sc=new SqlCommand ("insert into Patient_Details values('"+textBox1 +",'"+textBox2 +",'"+textBox3 +",'"+textBox4 +",'"+textBox5 +");",con );
为:
SqlCommand sc=new SqlCommand ("insert into Patient_Details values('"+ textBox1.Text +"','"+ textBox2.Text +"','"+ textBox3.Text +"','"+ textBox4.Text +"','"+ textBox5.Text +"');",con );
然后,转到http://www.w3schools.com/sql/sql_injection.asp并了解SQL注入攻击并更改代码以防止这种情况发生。 See this question for plenty of advice on how to achieve that
答案 2 :(得分:-1)
使用文本框的Text属性。
textbox1.Text// in the query.
SqlCommand sc=new SqlCommand ("insert into Patient_Details values('"+textBox1.Text +"','"+textBox2.Text +"','"+textBox3.Text +"','"+textBox4.Text +"','"+textBox5.Text +"');",con );
and of course the missing apostrphe and use parametrized query.