Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
hi all

i want to knw about a simple functionality that

how to insert data in ms-sql server 2005 with asp.net drop downlist control !

please help me . as i am beginner

thnks
Posted

1 solution

Hi ,
Try this it will be much better
C#
// make your connection in the web.config so you can use it easly and when you want to modfiey you will modified in on place
       using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
       {
           conn.Open();
           using (SqlCommand cmd = new SqlCommand("insert into dbo.cars(carID, Capicity, Luggage, Doors,Category,carname) values ('688', '5' , '9' , '8' ,  @parm , 'datsun')", conn))
           {
               //
               cmd.Parameters.AddWithValue("@parm", DropDownList2.SelectedValue);
               cmd.ExecuteNonQuery();
           }

       }

Connection in web.config
HTML
<configuration>
	<connectionstrings>
  <add name="testConnectionString" connectionstring="Data Source=.;Initial Catalog=test;Integrated Security=True">
   providerName="System.Data.SqlClient" />
 </add></connectionstrings></configuration>

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
syed armaan hussain 24-Apr-12 19:28pm    
thanks a lot .. it helpd me to learn about parameters

thumbz up!
Mohamed Mitwalli 25-Apr-12 9:51am    
your welcome :) by the way if it help you mark it as answered .
VJ Reddy 22-May-12 23:13pm    
Good answer. 5!
Mohamed Mitwalli 23-May-12 3:27am    
Thanks VJ :)

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