Hi...........Advance thanks of all you............
Please Help me, It's urgently.......
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Datta KharadPosted Jan 14, 2012, 6:16 AM
You can Insert value into sql server 2008 using stored procedure, try below code.
web.config
//---------------------------------------------
Used Stored procedure
CREATE PROCEDURE [dbo].[AddUser]
(
@FName varchar(50),
@LName varchar(50),
@DateOfBirth datetime,
@City varchar(50),
@State varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO UserDetails (FName, LName, DateOfBirth, City, State)
VALUES (@FName, @LName, @DateOfBirth, @City, @State)
END
//-----------------------------------------------------------------
//In C# Code
String ConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "AddUser";
cmd.Parameters.Add("@FName",SqlDbType.VarChar).Value = txtFName.Text.Trim();
cmd.Parameters.Add("@LName", SqlDbType.VarChar).Value = txtLName.Text.Trim();
cmd.Parameters.Add("@DateOfBirth", SqlDbType.DateTime).Value = txtDOB.Text.Trim();
cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = txtCity.Text.Trim();
cmd.Parameters.Add("@State", SqlDbType.VarChar).Value = txtState.Text.Trim();
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
lblMessage.Text = "Record inserted successfully";
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
Akhilesh PatelPosted Jan 14, 2012, 10:29 AM
Satyapriya NayakPosted Jan 14, 2012, 4:18 AM
Please refer the below link
http://www.codeproject.com/KB/database/SQL-2008-TableValue-Param.aspx
Thanks