Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL2005C#ASP.NET
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....

    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 3 Jan '13 - 10:38
Edited 3 Jan '13 - 10:40


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
  Permalink  
Comments
DinoRondelly - 3 Jan '13 - 18:02
Wow a little harsh but my 5 regardless ..
Sergey Alexandrovich Kryukov - 3 Jan '13 - 19:16
Harsh, this one?! What, never saw my answers? :-) (See also my comment below.) —SA
Christian Graus - 3 Jan '13 - 18:04
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:09
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 259
1 OriginalGriff 220
2 Mahesh Bailwal 159
3 CPallini 143
4 Maciej Los 140
0 Sergey Alexandrovich Kryukov 10,214
1 OriginalGriff 7,819
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid