Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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"];


So, once I get the name as R_Coder from the third party tool, I need to store it in database in tables.
Posted
Comments
ArunRajendra 21-Oct-13 1:38am    
Yes its possible.
JL_Coder 21-Oct-13 1:43am    
Ok. Any further help can you do? Obviously not asking for code, but some tutorials, or at least the mechanism to do it.
Thanks7872 21-Oct-13 1:55am    
Just write query for that.

insert into table values(myname.....);

Execute it. Whats the problem? This is not some thing that can be explained using TUTORIAL.

Hi,

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

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


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

C#
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;
 
Share this answer
 
Comments
JL_Coder 22-Oct-13 1:12am    
Hi. Thanks. it was helpful. And after some little help from above comments, I wrote the same code as yours and it worked fine. :)
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.
 
Share this answer
 
v2

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