C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Insertion into a table


Posted Date: 28 Aug 2008      Total Responses: 2

Posted By: Sankararaman       Member Level: Silver     Points: 1


Hell frirends

I have to two fields customer ID and Customer Name. I have written the procedure to insert records as follows:

PROCEDURE [dbo].[InsertCustomer] (
@Cust_code int,
@Cust_Name varchar(20)
) AS
INSERT INTO Users VALUES(@Cust_code, @Cust_Name)


Now I am calling from the c# to insert a value

SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["Buy4nowConnectionString"].ToString());
Conn.Open();

SqlCommand _cmd = new SqlCommand("procSelectUserGroup", Conn);

_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.AddWithValue("@InsertCustomer", "1,'test'");
SqlDataReader _reader = _cmd.ExecuteReader();


Please let me know, what I have to do to insert record (Now I am inserting this record directly)

If I add two controls in my ASP page as customer ID, cusotmer name,

how should I substitute. Please help me


My connection string working properly.

My advance thanks











Responses

Author: Ritesh N. Jain    28 Aug 2008Member Level: GoldRating:     Points: 6
change below line

_cmd.Parameters.AddWithValue("@InsertCustomer", "1,'test'");


with

_cmd.Parameters.AddWithValue("@Cust_code", tbCustCode.text);
_cmd.Parameters.AddWithValue("@Cust_Name ", tbCustName.text);



Author: ANIL PANDEY    29 Aug 2008Member Level: DiamondRating:     Points: 6
hi,


u can try this


PROCEDURE [dbo].[InsertCustomer] (
@Cust_code int,
@Cust_Name varchar(20)
) AS
INSERT INTO Users VALUES(@Cust_code, @Cust_Name)


Now I am calling from the c# to insert a value

SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["Buy4nowConnectionString"].ToString());
Conn.Open();

SqlCommand _cmd = new SqlCommand("procSelectUserGroup", Conn);

_cmd.CommandType = CommandType.StoredProcedure;

_cmd.Parameters.AddWithValue("@Cust_code", tbCustCode.text);
_cmd.Parameters.AddWithValue("@Cust_Name ", tbCustName.text);
SqlDataReader _reader = _cmd.ExecuteReader();


Thanks
Anil



Post Reply
You must Sign In to post a response.
Next : code for student forum
Previous : message box in asp.net
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use