diehard2007
عضو جدید
با سلام و خسته نباشيد . من در حال نوشتن يك برنامه تعميرگاه موبايل هستم همه چيز خوب پيش رفت تا رسيدم به پر كردن جدول واسط يعنى از دو جدول بايد اطلاعات خوانده بشه و در جدول سومى پر شود حالا چطورى مى تونم اين كار رو انجام بدم . البته يه كدى هم نوشتم نمى دونم درسته يا نه ؟ ممنون مى شم راهنماييم كنيد .
string d;
privatevoid btnAdd_Click(object sender, EventArgs e)
{
SqlConnection cn = newSqlConnection("Data Source=.;Initial Catalog=Mobile1;Integrated Security=True");
cn.Open();
SqlCommand cmd = newSqlCommand("insert into customers(c_name,c_tel)values('"+txtc_name.Text+"','"+txtc_tel.Text+"')insert into phones(ph_name,ph_s_number,ph_problem,ph_tarikh)values('"+txtph_name.Text+"','"+txtph_s_number.Text+"','"+txtph_problem.Text+"','"+txtph_tarikh.Text+"')",cn);
cmd.ExecuteNonQuery();
cn.Close();
cn = newSqlConnection("Data Source=.;Initial Catalog=ShopMobileYazdi;Integrated Security=True");
//find c_id
SqlConnection cn2 = newSqlConnection("Data Source=.;Initial Catalog=Mobile1;Integrated Security=True");
cn2.Open();
cmd = newSqlCommand("select c_id from customers where c_name='"+txtc_name.Text+"'and c_tel='"+txtc_tel.Text+"'");
cmd.Connection = cn;
int c_id;
c_id = (int)cmd.ExecuteScalar();
cn2.Close();
//find ph_id
SqlConnection cn3;
cn3 = newSqlConnection("Data Source=.;Initial Catalog=Mobile1;Integrated Security=True");
SqlCommand cmd2;
cmd2 = newSqlCommand("select ph_id from phones where ph_name='"+txtph_name.Text+"'");
cmd.Connection = cn3;
cn3.Open();
int ph_id;
ph_id = (int)cmd2.ExecuteScalar();
cn3.Close();
cmd = newSqlCommand("insert into orders (c_id,ph_id) values (" + c_id + "," + ph_id + ")");
cmd.Connection = cn;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
ShowData();
}
string d;
privatevoid btnAdd_Click(object sender, EventArgs e)
{
SqlConnection cn = newSqlConnection("Data Source=.;Initial Catalog=Mobile1;Integrated Security=True");
cn.Open();
SqlCommand cmd = newSqlCommand("insert into customers(c_name,c_tel)values('"+txtc_name.Text+"','"+txtc_tel.Text+"')insert into phones(ph_name,ph_s_number,ph_problem,ph_tarikh)values('"+txtph_name.Text+"','"+txtph_s_number.Text+"','"+txtph_problem.Text+"','"+txtph_tarikh.Text+"')",cn);
cmd.ExecuteNonQuery();
cn.Close();
cn = newSqlConnection("Data Source=.;Initial Catalog=ShopMobileYazdi;Integrated Security=True");
//find c_id
SqlConnection cn2 = newSqlConnection("Data Source=.;Initial Catalog=Mobile1;Integrated Security=True");
cn2.Open();
cmd = newSqlCommand("select c_id from customers where c_name='"+txtc_name.Text+"'and c_tel='"+txtc_tel.Text+"'");
cmd.Connection = cn;
int c_id;
c_id = (int)cmd.ExecuteScalar();
cn2.Close();
//find ph_id
SqlConnection cn3;
cn3 = newSqlConnection("Data Source=.;Initial Catalog=Mobile1;Integrated Security=True");
SqlCommand cmd2;
cmd2 = newSqlCommand("select ph_id from phones where ph_name='"+txtph_name.Text+"'");
cmd.Connection = cn3;
cn3.Open();
int ph_id;
ph_id = (int)cmd2.ExecuteScalar();
cn3.Close();
cmd = newSqlCommand("insert into orders (c_id,ph_id) values (" + c_id + "," + ph_id + ")");
cmd.Connection = cn;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
ShowData();
}