private void button2_Click(object sender, EventArgs e)
{ string s = textBox2.Text;
SqlConnection cn = new SqlConnection("Data Source=.\\SQLEXPRESS;DataBase=MyDatas;Integrated Security=True;");
cn.Open();
string str=("select Name from Stu where Id=s");
SqlCommand cmd=new SqlCommand(str,cn);
SqlDataReader Dr = cmd.ExecuteReader();
while (Dr.Read())
{
string name = Dr.GetString(0);
textBox3.Text = name;
} }就是那个查询条件查询学生的Id,怎么把文本框输入的s的值传给Id啊?????不会,,急啊,在线等各位大哥大姐帮忙!数据库C#
解决方案 »
- 求教一个面试题目
- C#类库中引用了别的Dll,在应用项目中使用C#类库时出现:无法找到入口点,如何解决?
- sql的datetime与c#中的datetime转换问题,老婆说做不出来不能吃饭明天,狂晕
- DataTable中使用的是继承DataColumn的MyColumn,序例化存到本地后,反序化时DataTable就变成了DataColun,而不是MyColumn,是什么原因?
- 窗体的title的问题,高手请进
- 如何在同一表单中的不同事件中共用一个dataset?
- 控制输入
- datetimepicker简单问题
- csc不工作了:
- 关于泛型约束的调用问题
- 关于测试驱动开发的疑问?
- C#中TeeChart曲线画法
最好用加参数的方式
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;namespace 连接
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// string b=a;
} private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
} private void Form1_Load(object sender, EventArgs e)
{
DataSet ds= new DataSet(); SqlConnection cn = new SqlConnection("Data Source=.\\SQLEXPRESS;DataBase=MyDatas;Integrated Security=True;");
string sql="select * from Stu";
cn.Open();
SqlDataAdapter da=new SqlDataAdapter(sql,cn);
da.Fill(ds);
dataGridView1.DataSource=ds.Tables[0];
} private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int row = dataGridView1.CurrentCell.RowIndex;
textBox1.Text = dataGridView1[0, row].Value.ToString();
} private void button2_Click(object sender, EventArgs e)
{ string s = textBox2.Text;
SqlConnection cn = new SqlConnection("Data Source=.\\SQLEXPRESS;DataBase=MyDatas;Integrated Security=True;");
cn.Open();
string str=("select Name from Stu where Id="+s);
SqlCommand cmd=new SqlCommand(str,cn);
SqlDataReader Dr = cmd.ExecuteReader();
while (Dr.Read())
{
string name = Dr.GetString(0);
textBox3.Text = name;
} }