Insert Command Statement Help

B

Brian Conway

Can anyone give me a quick little break down of what I would need to do to
insert information into a database onClick of and Submit button? I am new
to all of this and have done it with datagrids, but want to do it with just
textboxes filled in and on click of the Submit button that it would take
those boxes and insert a record into the database. This is for C#. below
is a little of what I have on the submit button but I don't think it is
correct.

private void btnSubmit_Click(object sender, System.EventArgs e)

{

this.oleDbInsertCommand1.CommandText = @"INSERT INTO
CONFERENCE.REQUEST(CUID, REQ_NUM, REQ_TYPE, CREATE_DT, START_DT, END_DT,
START_TM, END_TM, REQ_TTL, ATTENDEE_QTY, SETUP_DT, SETUP_TM, REQ_DESC,
CATERING_IND, WALK_THRU_IND, STORAGE_IND, BREAKOUT_RM_IND, MATERIALS_IND,
SPECIAL_REQ_TXT, REQ_STATUS, UPDATE_DT, UPDATED_BY_CUID,
CARD_EXPIRATION_VALUE, CHARGE_CD, BILL_METHOD_CD) VALUES (?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

this.oleDbInsertCommand1.Connection = this.oleDbConnection1;

this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CUID",
System.Data.OleDb.OleDbType.VarChar, 8, "CUID"));

this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("REQ_NUM",
System.Data.OleDb.OleDbType.Decimal, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(10)),
((System.Byte)(0)), "REQ_NUM", System.Data.DataRowVersion.Current, null));
 
M

Miha Markic [MVP C#]

Hi Brian,

Assuming the sql command is correct, you'll have to add a parameter for each
? and assign a value (.Value property) to each.
 
B

Brian Conway

Can you give me an example of how to do this. Are the insert commands in
the correct spot? Should I be putting these in the Submit button click
area?




Miha Markic said:
Hi Brian,

Assuming the sql command is correct, you'll have to add a parameter for each
? and assign a value (.Value property) to each.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Brian Conway said:
Can anyone give me a quick little break down of what I would need to do to
insert information into a database onClick of and Submit button? I am new
to all of this and have done it with datagrids, but want to do it with just
textboxes filled in and on click of the Submit button that it would take
those boxes and insert a record into the database. This is for C#. below
is a little of what I have on the submit button but I don't think it is
correct.

private void btnSubmit_Click(object sender, System.EventArgs e)

{

this.oleDbInsertCommand1.CommandText = @"INSERT INTO
CONFERENCE.REQUEST(CUID, REQ_NUM, REQ_TYPE, CREATE_DT, START_DT, END_DT,
START_TM, END_TM, REQ_TTL, ATTENDEE_QTY, SETUP_DT, SETUP_TM, REQ_DESC,
CATERING_IND, WALK_THRU_IND, STORAGE_IND, BREAKOUT_RM_IND, MATERIALS_IND,
SPECIAL_REQ_TXT, REQ_STATUS, UPDATE_DT, UPDATED_BY_CUID,
CARD_EXPIRATION_VALUE, CHARGE_CD, BILL_METHOD_CD) VALUES (?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

this.oleDbInsertCommand1.Connection = this.oleDbConnection1;

this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("CUID",
System.Data.OleDb.OleDbType.VarChar, 8, "CUID"));

this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("REQ_NUM",
System.Data.OleDb.OleDbType.Decimal, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(10)),
((System.Byte)(0)), "REQ_NUM", System.Data.DataRowVersion.Current, null));
 
M

Miha Markic [MVP C#]

Hi,

Brian Conway said:
Can you give me an example of how to do this. Are the insert commands in
the correct spot?

I guess so.

Should I be putting these in the Submit button click

You might define the command and parameters at class level somewhere.
Within the submit method you just set parameter values.
See the
Inserting Data Into a SQL Database
..net help topic - it will give you an idea of what to do.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Miha Markic said:
Hi Brian,

Assuming the sql command is correct, you'll have to add a parameter for each
? and assign a value (.Value property) to each.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Brian Conway said:
Can anyone give me a quick little break down of what I would need to
do
 
Top