Pulling a GUID from a drop down menu value and include it into another table.

Discussion in 'C#' started by rainmanjam, Jun 12, 2009.

  1. #1
    I am trying to reinsert into a new table a GUID based on the selected value of a drop down menu. I am able to retrieve the GUID with the following code.



    1                con.Open();
    2                reader = check.ExecuteReader();
    3    
    4                if (reader != null)
    5                    while (reader.Read())
    6                    {
    7                        var couItem = new ListItem();
    8                        var comNameItem = new ListItem();
    9                        LblStatus.Text += reader["Cou"] + "," + reader["ComName"] + "," + reader["GUID"];
    10                       Item.Text = reader["ComName"].ToString();
    11                       Item.Value = reader["ComGUID"].ToString(); 
    12                       Item.Text = reader["Cou"].ToString();
    13                       Item.Value = reader["Cou"].ToString();
    14                       Dpd.Items.Add(couItem);
    15                       Dpd.Items.Add(comNameItem);
    16                   }
    17               if (reader != null) reader.Close();
    Code (markup):
    So I am able to see the GUID in the LblStatus and in the drop down menu values in the HTML Code

    When I use the following code:



    1        protected void BnAddLocation_Click(object sender, EventArgs e)
    2        {
    3            int userId = CSContext.Current.User.UserID;
    4            string insertSQL = "INSERT INTO cs_L (";
    5            insertSQL += "UserID, GUID, Number) ";
    6            insertSQL += "VALUES ('";
    7            insertSQL += userId + "','";
    8            insertSQL += Dpd.SelectedValue + "','"; //This line should retrieved the selected value from the drop down menu.
    9            insertSQL += Number.Text + "')";
    10   
    11           var con = new SqlConnection(blah);
    12           var insert = new SqlCommand(insertSQL, con);
    13           
    14           try
    15           {
    16               con.Open();
    17               int count = insert.ExecuteNonQuery();
    18               LblNotification.Text = count + " records added.";
    19               LblNotification.Text += Dpd.DataValueField;
    20           }
    Code (markup):
    So I can not retrieve the information from the dropdown menu to insert into the GUID table of the new database. I may have messed up some of the code trying to sanitize it.
     
    rainmanjam, Jun 12, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    Is the code throwing an exception and have you used the debugger to step through the code? Also, lines 10-13 appear to be overwriting the text and value properties. Is this correct? I do not know your requirements thus the question.
     
    Social.Network, Jun 12, 2009 IP
  3. rainmanjam

    rainmanjam Peon

    Messages:
    155
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Its not overwriting.. the code is just chopped.
     
    rainmanjam, Jun 12, 2009 IP