我可以单击列表框中的一项,例如ID。名称 。在收件箱中的数据库中显示手机号码
enter
public frmmali()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection("Data Source=192.168.61.4;User ID=Hospital;Password=hsoftsa;Initial Catalog=institute");
SqlCommand cmd = new SqlCommand();
public string Query { get; private set; }
private void toolStripButton8_Click(object sender, EventArgs e)
{
this.Close();
}
void BindGrid()
{
dgvmali.AutoGenerateColumns = false;
}
//void Display()
//{
// DataSet ds = new DataSet();
// SqlDataAdapter adp = new SqlDataAdapter();
// adp.SelectCommand = new SqlCommand();
// adp.SelectCommand.Connection = con;
// adp.SelectCommand.CommandText = "select * from rgstude";
// adp.Fill(ds, "rgstude");
// //dataGridView1.DataSource = ds;
// dataGridView1.AutoGenerateColumns = false;
//}
private void frmmali_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataBase db = new DataBase();
dt = db.MySelect("select * from rgstude");
listBox1.DataSource = dt;
listBox1.DisplayMember = "name";
dt = db.MySelect("select * from semestarsenfha");
cmbsemestar.DataSource = dt;
cmbsemestar.DisplayMember = "smestar";
/////////
Random rd = new Random();
string[] texts =
{
"سلام رو زبخیر",
"این متن تست هست",
"فرقی نمیکنه فقط تیست می کنم",
};
int index = rd.Next(0, texts.Length);
txtsokhan.Text = texts[index];
Display();
}
private void listboxname_MouseUp(object sender, MouseEventArgs e)
{
//txtid1.Text = listBox1.DisplayMember.ToString();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand();
adp.SelectCommand.Connection = con;
adp.SelectCommand.CommandText = "select * from rgstude where idrgstude like '%' + @s + '%' ";
adp.SelectCommand.Parameters.AddWithValue("@S", textBox1.Text + "%");
DataTable dt = new DataTable();
adp.Fill(dt);
listBox1.DataSource = dt;
listBox1.DisplayMember = "name";
//DataSet ds = new DataSet();
//SqlDataAdapter adp = new SqlDataAdapter();
//adp.SelectCommand = new SqlCommand();
//adp.SelectCommand.Connection = con;
//adp.SelectCommand.CommandText = "select * from rgstude where name like '%' + @s + '%' ";
//adp.SelectCommand.Parameters.AddWithValue("@S", textBox1.Text + "%");
//DataTable dt = new DataTable();
//adp.Fill(dt);
//listBox1.DataSource = dt;
//listBox1.DisplayMember = "name";
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
new frmfees().ShowDialog();
}
void Display()
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand();
adp.SelectCommand.Connection = con;
adp.SelectCommand.CommandText = "select * from rgstude";
adp.Fill(ds, "rgstude");
dgvmali.DataSource = ds;
dgvmali.DataMember = "rgstude";
dgvmali.AutoGenerateColumns = false;
dgvmali.Columns[0].HeaderText = "نام ";
dgvmali.Columns[1].HeaderText = "ولد ";
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand();
adp.SelectCommand.Connection = con;
adp.SelectCommand.CommandText = "select * from rgstude where idrgstude Like '%' + @S+ '%'";
adp.SelectCommand.Parameters.AddWithValue("@S", textBox3.Text + "%");
adp.Fill(ds, "rgstude");
dgvmali.DataSource = ds;
dgvmali.DataMember = "rgstude";
}
private void dgvmali_MouseUp(object sender, MouseEventArgs e)
{
txtid1.Text = dgvmali[0, dgvmali.CurrentRow.Index].Value.ToString();
txtname.Text = dgvmali[1, dgvmali.CurrentRow.Index].Value.ToString();
}
private void listBox1_Click(object sender, EventArgs e)
{
}
}
这里