.NET Framework Developer Center > Using Forums Forums > Where is the Forum For…? > inserting the database from checkboxlist control in asp.net
Ask a questionAsk a question
 

Questioninserting the database from checkboxlist control in asp.net

  • Wednesday, November 04, 2009 11:51 AMvasant asp.net developer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    hi am not able to insrt values into database when user clicks on checbox , i have six checkboxes , how do i do this here is the code .
    string connec = @"Data Source=.\SQLEXPRESS;Initial Catalog=UserRegistration;Integrated Security=True"; //sqlconnection
    SqlConnection objcon = new SqlConnection(connec);
    string QUERY = "insert into Test(project)values (@project)";///my database
    SqlCommand cmd = new SqlCommand(QUERY);
    objcon.Open();
    cmd.Parameters.AddWithValue("@project", CheckBoxList1.SelectedItem.Text);
    int result1 = cmd.ExecuteNonQuery();
    if (result1 == 1)
    {
        Response.Write("user added done");
    }
    string taxes = "";
    foreach (ListItem item in CheckBoxList1.Items)
    {
        if (item.Selected) 
            taxes = taxes + item.Value + ","; 
    }
    
    • Moved byKarel ZikmundMSFTWednesday, November 04, 2009 6:27 PMWrong forum (From:Building Development and Diagnostic Tools for .Net)
    • Edited byKarel ZikmundMSFTWednesday, November 04, 2009 6:22 PMFormat code to readable form
    •  

All Replies

  • Wednesday, November 04, 2009 6:27 PMKarel ZikmundMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What exactly doesn't work? (Which line of code fails and what is the error code - did you check various logs?)
    Do you have write access to the database? Does read from the database work?

    BTW: Your question doesn't seemt o be ASP.NET specific - this looks like general problem to access database. If it is ASP.NET specific, please use http://forums.asp.net.
    Also this is wrong forum for either question - read the sticky post of this forum.

    -Karel