Click here to Skip to main content
15,883,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying below code to display Complaint_no from Call_reg table as well as tech_name from new_tech table from database and after selecting complaint no. from dropdownlist, i want to choose technician name from another dropdownlist and then on button click to be inserted in Call_Allocation table

On button click can somebody suggest me cmd command query for inserting the same.


mentioned in bold.

Can somebody help me please....

C#
SqlCommand cmd;
SqlDataReader dr;
private string s;
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ddlComplaint.Items.Insert(0, new ListItem("---Select---", "---Select---"));
        FillDropDownList();
        ddlAllow.Items.Insert(0, new ListItem("---Select---", "---Select---"));
        FillTechnicianDropDownList();
    }
}



// Fill Dropdownlist
public void FillDropDownList()
{
    s = WebConfigurationManager.ConnectionStrings["Callregister_connectionstring"].ConnectionString;
    con = new SqlConnection(s);
    con.Open();
    cmd = new SqlCommand("Select Complaint_no from Call_Reg where Status='Open'" , con);
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        ddlComplaint.Items.Add(dr[0].ToString());
    }
    dr.Close();
    con.Close();
}

// Show data in GridView
protected void btnSearch_Click(object sender, EventArgs e)
{
    s = WebConfigurationManager.ConnectionStrings["Callregister_connectionstring"].ConnectionString;
    con = new SqlConnection(s);
    con.Open();
    cmd = new SqlCommand("Select * from Call_Reg where Complaint_no='" + ddlComplaint.SelectedItem.ToString() + "'", con);
    dr = cmd.ExecuteReader();
    GridView2.DataSource = dr;
    GridView2.DataBind();
    dr.Close();
    con.Close();
}

// Fill Technician
public void FillTechnicianDropDownList()
{
    s = WebConfigurationManager.ConnectionStrings["Callregister_connectionstring"].ConnectionString;
    con = new SqlConnection(s);
    con.Open();
    cmd = new SqlCommand("Select Fname from New_Tech", con);
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        ddlAllow.Items.Add(dr[0].ToString());
    }
    dr.Close();
    con.Close();
}

protected void btnAllo_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("SERVER=KSHITIJA-PC; Initial Catalog=CRM;Integrated Security=True");
    //SqlCommand cmd = new SqlCommand("Update Call_reg set status='Assigned' Where Complaint_no= '" + ddlComplaint.SelectedItem.ToString() + "'", con);
    SqlCommand cmd = new SqlCommand(" insert into Call_Allocation values( "", con);
    try
    {
        con.Open();

        int i = cmd.ExecuteNonQuery();
        //int a = cmd1.ExecuteNonQuery();
        if (i  == 1)
        {
            ddlComplaint.SelectedItem.Text = "";
            EO.Web.MsgBoxButton mb = new EO.Web.MsgBoxButton("OK");
            MsgBox1.Show("Message: ", "Call Assigned to Technician", null, mb);
         }

    }
    catch (Exception ex)
    {
        EO.Web.MsgBoxButton mb = new EO.Web.MsgBoxButton("OK");
        MsgBox1.Show("Error: ", ex.Message, null, mb);

    }
    con.Close();
}
Posted
Updated 3-Jan-13 10:40am
v2

1 solution

please stop asking this over and over again. You've asked it five times now. If you just keep asking the same thing, you're not progressing. If you really can't understand this at all, and you, for some insane reason, are in a situation where you HAVE to write something you have no clue how to write, you'd do better spending a day reading about how to write this SQL, than spending a week asking it over and over until someone decides to spend an hour doing your job for you, so you can blindly cut and paste an answer you do not understand
 
Share this answer
 
Comments
DinoRondelly 3-Jan-13 18:02pm    
Wow a little harsh but my 5 regardless ..
Sergey Alexandrovich Kryukov 3-Jan-13 19:16pm    
Harsh, this one?! What, never saw my answers? :-)
(See also my comment below.)
—SA
Christian Graus 3-Jan-13 18:04pm    
If this guy doesn't stop asking the same thing, and actually follow the advice he's been given ( by me at least four times, and by others ), then he's not going to get his work done. He needs a push in the right direction. He's told me on another version of this question that he's going to do what I've been telling him, so I think it worked
Sergey Alexandrovich Kryukov 3-Jan-13 19:09pm    
Very correct and convincing motivation. I'm with you here. (A 5.)
In real life, I knew the situations, when even a good kick on the ass, performed on some select talents, can be considered as a valuable and effective help. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900