java程序啊忘了jdbc的连接方式了,不过觉得你这个setObject的方法定义的有问题不过我觉得for(int i=0;i<obj.length;i++){
ps.setObject(i+1,obj[i]);
}
这个有问题,你要给绑定变量赋值的时候,要说明数据类型吧给你了C#的参考一下
*/
private void button1_Click(object sender, EventArgs e)
{
//实例化Connection对象
SqlConnection connection = new SqlConnection("server=localhost;database=dbtest1;uid=sa;pwd='1");
//实例化Command对象
string sql = "select * from t_1 where Cloumn1=@Cloumn1";
SqlCommand command = new SqlCommand(sql);
//SqlDbType.Int变量的类型
SqlParameter parameter = new SqlParameter("@Cloumn1", SqlDbType.Int);
parameter.Value = this.textBox1.Text.Trim();
command.Parameters.Add(parameter);//添加参数
command.Connection = connection; //实例化DataAdapter
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable data = new DataTable();
adapter.Fill(data);
if (data.Rows.Count > 0)
{
this.label1.Text = "查询成功:" + data.Rows[0][1].ToString();
}
else
{
this.label1.Text = "没有查询到数据";
}
connection.Close();
}
ps.setObject(i+1,obj[i]);
}
这个有问题,你要给绑定变量赋值的时候,要说明数据类型吧给你了C#的参考一下
*/
private void button1_Click(object sender, EventArgs e)
{
//实例化Connection对象
SqlConnection connection = new SqlConnection("server=localhost;database=dbtest1;uid=sa;pwd='1");
//实例化Command对象
string sql = "select * from t_1 where Cloumn1=@Cloumn1";
SqlCommand command = new SqlCommand(sql);
//SqlDbType.Int变量的类型
SqlParameter parameter = new SqlParameter("@Cloumn1", SqlDbType.Int);
parameter.Value = this.textBox1.Text.Trim();
command.Parameters.Add(parameter);//添加参数
command.Connection = connection; //实例化DataAdapter
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable data = new DataTable();
adapter.Fill(data);
if (data.Rows.Count > 0)
{
this.label1.Text = "查询成功:" + data.Rows[0][1].ToString();
}
else
{
this.label1.Text = "没有查询到数据";
}
connection.Close();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货