如何使用asp.net drop downlist控件在ms-sql server 2005中插入数据 [英] how to insert data in ms-sql server 2005 with asp.net drop downlist control
本文介绍了如何使用asp.net drop downlist控件在ms-sql server 2005中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我想了解一个简单的功能,
如何使用asp.net drop downlist控件在ms-sql server 2005中插入数据!
请帮我 .我是初学者
thnks
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
推荐答案
试试这个会更好的
Hi ,
Try this it will be much better
// 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();
}
}
web.config中的连接
Connection in web.config
<configuration>
<connectionstrings>
<add name="testConnectionString" connectionstring="Data Source=.;Initial Catalog=test;Integrated Security=True">
providerName="System.Data.SqlClient" />
</add></connectionstrings></configuration>
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于如何使用asp.net drop downlist控件在ms-sql server 2005中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文