熟悉C#的进来我只是想把textBox1中的数值插入到本机的model数据库里去
(我的数据库没有密码 )
private void button1_Click(object sender, System.EventArgs e)
{
string tb = textBox1.Text;
InsertTable(tb); }
public void InsertTable(string tbb)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString ="data source=.;initial catalog=model;persist security info=False;user id=sa;password=;";
SqlCommand cmm = new SqlCommand();
try
{
conn.Open();
cmm.Connection = conn;
cmm.Parameters.Add("@id",tbb);
cmm.CommandText = "insert into h1 (id) values (@id)";
}
catch(Exception ex)
{
string e = ex.Message;
}
finally
{
conn.Close();
cmm.Dispose();
} }
我这样写为什么在数据库表里没有插入数据呢
帮我分析下,是我连接数据库的问题吗
有熟悉原因的麻烦多多指教(在线等)
(我的数据库没有密码 )
private void button1_Click(object sender, System.EventArgs e)
{
string tb = textBox1.Text;
InsertTable(tb); }
public void InsertTable(string tbb)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString ="data source=.;initial catalog=model;persist security info=False;user id=sa;password=;";
SqlCommand cmm = new SqlCommand();
try
{
conn.Open();
cmm.Connection = conn;
cmm.Parameters.Add("@id",tbb);
cmm.CommandText = "insert into h1 (id) values (@id)";
}
catch(Exception ex)
{
string e = ex.Message;
}
finally
{
conn.Close();
cmm.Dispose();
} }
我这样写为什么在数据库表里没有插入数据呢
帮我分析下,是我连接数据库的问题吗
有熟悉原因的麻烦多多指教(在线等)
cmm.ExecuteNonQuery();
cmm.ExecuteNonQuery();