I have two tables pre_enquiry & enquiry ,enquiryno is primary key of pre_enquiry table,username is also stored in it.In enquiry webform if i enter username then related enquiryno. should be autofilled in textbox ,& delete the record from pre_enquiry table
I have done following
public partial class EnquiryForm : System.Web.UI.Page
{
SqlConnection cn,cn1;
SqlCommand cmd;
//DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
// if (!IsPostBack)
//{
// cn = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);
// cmd = new SqlCommand("select EnquiryNo from Pre_Enquiry where(Uname=" + TextBox1.Text + ")");
// cn.Open();
// tr=cmd.ExecuteReader();
// while (tr.Read)
// {
// int i = tr["EnquiryNo"];
//}
// tr.Close();
//cn.Close();
//}
}
protected void Button2_Click(object sender, EventArgs e)
{
// cn = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);
// TxtEnqNo.Text = Convert.ToString(cmd = new SqlCommand("select EnquiryNo from Pre_Enquiry Where(Uname=" + TextBox1.Text + ");", cn));
// //TxtEnqNo.Text = Convert.ToString("EnquiryNo");
// cn.Open();
// cmd.ExecuteNonQuery();
// cn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);
//cmd = new SqlCommand("select EnquiryNo.,enqDate,Uname,BranhName,TelNo from Pre_Enquiry");
//cmd = new SqlCommand("Insert into enquiry values('" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + TxtEnqNo.Text="select EnquiryNo from Pre_Enquiry where (Uname="+TextBox1.Text+")" + "','" + DropDownList3.SelectedItem.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + Convert.ToInt32(TextBox3.Text) + "','" + Convert.ToInt32(TextBox4.Text) + "','" + Convert.ToInt32(TextBox5.Text) + "','" + DropDownList4.SelectedItem.Text + "/" + DropDownList6.SelectedItem.Text + "/" + DropDownList7.SelectedItem.Text + "','" + DropDownList5.SelectedItem.Text + "','" + TextBox6.Text + "','" + TextBox8.Text + "','" + RadioButtonList2.SelectedItem.Text + "','" + TextBox9.Text + "','" + RadioButtonList3.SelectedItem.Text + "','" + RadioButtonList4.SelectedItem.Text + "','" + RadioButtonList5.SelectedItem.Text + "','" + TextBox7.Text + "');", cn);
cmd = new SqlCommand("Insert into enquiry values('" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + TxtEnqNo.Text + "','" + DropDownList3.SelectedItem.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + Convert.ToInt32(TextBox3.Text) + "','" + Convert.ToInt32(TextBox4.Text) + "','" + Convert.ToInt32(TextBox5.Text) + "','" + DropDownList4.SelectedItem.Text + "/" + DropDownList6.SelectedItem.Text + "/" + DropDownList7.SelectedItem.Text + "','" + DropDownList5.SelectedItem.Text + "','" + TextBox6.Text + "','" + TextBox8.Text + "','" + RadioButtonList2.SelectedItem.Text + "','" + TextBox9.Text + "','" + RadioButtonList3.SelectedItem.Text + "','" + RadioButtonList4.SelectedItem.Text + "','" + RadioButtonList5.SelectedItem.Text + "','" + TextBox7.Text + "');", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//dt=new DataTable("Pre_Enquiry");
//tr = new DataTableReader(dt);
// cmd=new SqlCommand("select EnquiryNo from Pre_Enquiry where(Uname="+TextBox1.Text+")");
int i;
cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);
cmd = new SqlCommand("select EnquiryNo from Pre_Enquiry where(Uname=@uname);", cn1);
cn1.Open();
SqlDataReader tr;
tr=cmd.ExecuteReader();
while (tr.Read())
{
i = Convert.ToInt32(tr["EnquiryNo"]);
TxtEnqNo.Text = Convert.ToString(i);
//TxtEnqNo.Text=cmd.Parameters.Add("@EnquiryNo").Value;
}
tr.Close();
cn1.Close();
}
}