从C#中的Request.Form []获取值后直接向数据库提交数据 [英] Submitting data to database directly after getting the values from Request.Form[] in C#

查看:236
本文介绍了从C#中的Request.Form []获取值后直接向数据库提交数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我有疑问或疑问。我正在使用一些第三方工具,我在C#中使用request.Form []获取一些值。因此,在使用Request.Form []获取C#中的值之后,我希望将这些值直接发送到SQL Server的数据库。可能吗?如果有人知道,只想要意见。谢谢。例如,我有这行代码。



Well, I have a doubt or question. I am having some third party tool from which I am getting some values using request.Form[] in C#. So, after getting the values in C# using Request.Form[] I want to send those values directly to Database that is SQL server. Is it possible? Just want opinions if anyone knows. Thank you. For example, I have this line of code.

string myname=Request.Form["MyName"];





因此,一旦我从第三方工具获得名称为R_Coder,我需要将其存储在表格的数据库中。



So, once I get the name as R_Coder from the third party tool, I need to store it in database in tables.

推荐答案





假设您从request.form获取c#中的名称;



Hi,

Lets say you get the name from the request.form in c# as;

string tName = Request.Form["Name"];





然后你可以存储这个在sql server数据库中;





Then you can store this in the sql server database as;

SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adap = new SqlDataAdapter();
DataTable dt = new DataTable();

con.Open("...your DB connection string goes here...");
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into databaseTable(name)values(tName)";
cmd.CommandTimeOut = 10000;

adap.SelectCommand = cmd;
adap.Fill(dt);
con.Close();





这些值应该已插入数据库中。

希望这有帮助;



The values should have been inserted in the database.
Hope this helps;


更好的是你编写一个存储过程,而不是从你的应用程序传递insert sql,否则你需要检查sql注入。

从中获取值请求执行此sp的请求对象。它会将值存储到您的数据库中。它对您来说是安全的。



要执行存储过程,您可以使用ADO.NET或Microsoft模式并实践企业数据访问应用程序块。
Better you write a stored procedure instead of passing insert sql from your application otherwise you need to check sql injection.
After getting value from requrest object you just execute this sp. It will store value to your database. It will be safe for you.

To execute stored procedure either you can use ADO.NET or Microsoft pattern and practices Enterprise data access application block.


这篇关于从C#中的Request.Form []获取值后直接向数据库提交数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆