本文介绍了sqlDataSource并使用Insert命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我对.net框架工作不熟悉,我想在sql server中创建一张表,并希望使用UI前端和页面填充数据.逐步过程是什么,并提供一些用于插入数据的代码

Hi ,
I am new to .net frame work.I want to craete a table in sql server and want to populate the data using a UI front and page.What are the step by step procedures and provide some code for insertion of data

推荐答案

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }




如何提供连接字符串以执行此命令?"

最简单的方法是使用VS:
尝试使用服务器资源管理器"窗格在VS中建立连接.
1)打开服务器资源管理器.
2)右键单击数据连接",然后选择添加连接"
3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接"按钮.
4)连接正常后,按确定"
5)在服务器资源管理器"窗格中突出显示您的数据库,然后查看属性"窗格.将显示一个连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中.




"How to provide connection string to execute this command?"

Easiest way is to use VS:
Try setting up a connection in VS with the Server Explorer pane.
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.


这篇关于sqlDataSource并使用Insert命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 14:43
查看更多