gpt4 book ai didi

c# - 数据库中没有发生数据插入

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:57 26 4
gpt4 key购买 nike

我正在尝试将数据插入数据库。连接工作正常。但是我无法插入数据,我也不知道为什么。该表只是没有得到更新。

string ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Kaushalya\\Documents\\NewAgain.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

SqlCommand cmd = new SqlCommand("Insert into Tabel1(name) VALUES (@UserName);",conn);
cmd.Parameters.Add(new SqlParameter("@UserName", Convert.ToInt32(0)));

测试时连接正常。但是,我无法对数据库执行任何操作。

最佳答案

您需要执行命令对象。

cmd.ExecuteNonQuery();

更多信息 here .

关于c# - 数据库中没有发生数据插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6021260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com