小编ami*_*ish的帖子

SqlCommand INSERT查询不会将数据插入数据库

我正在使用Visual Studio 2013.

在下面的代码MessageBox.Show("Connected to database")中正确显示,但SQL查询未将数据插入数据库表.

当我手动插入数据时,它插入没有任何问题.但不幸的是,数据无法插入button_click命令.

private void DataAdd_Load(object sender, EventArgs e)
{
    try
    {
        conn = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=Pathname;Integrated Security=True;Connect Timeout=30");
        conn.Open();
        MessageBox.Show("Connected to database");
        cmd = new SqlCommand("INSERT INTO datains (name, dob, gender, occupation, height, weight, relation, polexpo) values('abc', '22-Aug-2001', 'Male', 'qwe2', '23', '431', 'qw23e', 'asqwed');", conn);
    }
    catch (Exception e1)
    {
        MessageBox.Show("Connection failed");
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么或我错过了什么?

.net c# sql database sqlcommand

0
推荐指数
1
解决办法
170
查看次数

标签 统计

.net ×1

c# ×1

database ×1

sql ×1

sqlcommand ×1