oscar数据库临时表数据插入后查不到

oscar数据库临时表数据插入后查不到,第1张

未提交。

需要点击commit。

否则只在你运行的时候提示成功,其实没真正的插入到数据库中,换到另一个会话中,你的数据就不在了。

添加数据库是,遇到是否将数据库复制到目标文件夹时选择“否”。如果选选“是”,每次启动程序,都要被复制,信息被覆盖,所以看到数据没有变化。你在 工程目录/bin/debug/能看到那个数据库,说明你选了“是”,在这里直接打开调试生产的EXE文件,数据能保存的话,证明就是这个问题。

C#代码:

using System

using System.Collections.Generic

using System.Text

using System.Data.SqlClient

namespace dd

{

class Program

{

static void Main(string[] args)

{

string str="server=.database=testuid=sapwd=sa"

SqlConnection conn = new SqlConnection(str)

string CommandText="insert into test(test1,test2) values(90,30) SELECT CAST(scope_identity() AS int)"---返回最后一次插入数据的id

SqlCommand cmd = new SqlCommand(CommandText, conn)

conn.Open()

int i=(int)cmd.ExecuteScalar()

conn.Close()

Console.WriteLine(i)

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9631494.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存