关于web form内容的添加 objConnection.Open();要放在前面,然后insertCommand.Connection=objConnection; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数据库操作问题-_-!objConnection.Open();SqlCommand insertCommand = new SqlCommand(insertStr, objConnection); 我在 web form中==明明是winform 我有一个SQL数据库EXAMPLE,里面有一个表 ALL,结构如下 id content time status ==楼主,你这一个表名和四个字段中all是SQL的运算符(这个最关键),content time status 都是sql的关键字..局部变量的名字又和控件的名字相同string content = content.Text; string time = time.Text; 修改后的程序如下private void button1_Click(object sender, EventArgs e){ string strConnection = @"server=(local);uid=sa;pwd=sa;database=example"; SqlConnection objConnection = new SqlConnection(strConnection); string insertStr = " INSERT INTO [All] (content,time) VALUES (@content,@time)"; SqlCommand insertCommand = new SqlCommand(insertStr, objConnection); insertCommand.Parameters.AddWithValue("@content", content.Text); insertCommand.Parameters.AddWithValue("@time", time.Value.ToString()); objConnection.Open(); insertCommand.ExecuteNonQuery(); objConnection.Close(); } c# 如何对正写入的文件进行读操作? 0.01到99999 9999.99的正则表达式?? 急急急 如何删除listview中选中的行? 请教DropDownList取值为什么总是一样 数据集插入记录返回0,请高手帮助 问一个想不明白的问题,大神们请给个解答,万分感谢. 急救 请问 “2004年7月20日” 与“13:23”的正则怎么写? 第一次做系统项目不知道从哪下手??求大神指导 谁能帮我写个在QQ游戏里自动发言的程序 我在项目添加一个新窗体,编译后怎么提示项目未加载
objConnection.Open();
SqlCommand insertCommand = new SqlCommand(insertStr, objConnection);
==
明明是winform
id content time status
==
楼主,你这一个表名和四个字段中all是SQL的运算符(这个最关键),content time status 都是sql的关键字..局部变量的名字又和控件的名字相同
string content = content.Text;
string time = time.Text; 修改后的程序如下
private void button1_Click(object sender, EventArgs e)
{
string strConnection = @"server=(local);uid=sa;pwd=sa;database=example";
SqlConnection objConnection = new SqlConnection(strConnection);
string insertStr = " INSERT INTO [All] (content,time) VALUES (@content,@time)";
SqlCommand insertCommand = new SqlCommand(insertStr, objConnection);
insertCommand.Parameters.AddWithValue("@content", content.Text);
insertCommand.Parameters.AddWithValue("@time", time.Value.ToString());
objConnection.Open();
insertCommand.ExecuteNonQuery();
objConnection.Close();
}