|
-
Feb 3rd, 2004, 05:34 PM
#1
Thread Starter
Fanatic Member
Write to SQL db
When I run this code, I get no error. But the data does show up in SQL...any thoughts?
Code:
private void bSubmit_Click(object sender, System.EventArgs e)
{
string sconn;
string insertCommand;
string to = tWhoTo.Text; //Request.Form("fDriveBy").(tWhoTo);
sconn = "Provider=SQLOLEDB;Data Source=DOGFISH;InitialCatalog=DrvBy;Integrated Security=SSPI;";
insertCommand = "Insert into SYS_DRVBY(WhoFrom, WhoTo, dt, Comments) values('" + to + "','" + to + "','" + "11/01/2001" + "','" + "this is a test" + "')";
OleDbConnection conn = new OleDbConnection(sconn);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand(insertCommand,conn);
}
-
Feb 3rd, 2004, 05:49 PM
#2
Frenzied Member
you aren't executing the query. Try the code below
VB Code:
private void bSubmit_Click(object sender, System.EventArgs e)
{
string sconn;
string insertCommand;
string to = tWhoTo.Text; //Request.Form("fDriveBy").(tWhoTo);
sconn = "Provider=SQLOLEDB;Data Source=DOGFISH;InitialCatalog=DrvBy;Integrated Security=SSPI;";
insertCommand = "Insert into SYS_DRVBY(WhoFrom, WhoTo, dt, Comments) values('" + to + "','" + to + "','" + "11/01/2001" + "','" + "this is a test" + "')";
OleDbConnection conn = new OleDbConnection(sconn);
OleDbCommand cmd = new OleDbCommand(insertCommand,conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
Last edited by Memnoch1207; Feb 3rd, 2004 at 05:55 PM.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Feb 3rd, 2004, 05:55 PM
#3
Thread Starter
Fanatic Member
I get this error:
No overload for method 'ExecuteNonQuery' takes '2' arguments
-
Feb 3rd, 2004, 06:00 PM
#4
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Feb 3rd, 2004, 06:05 PM
#5
Thread Starter
Fanatic Member
OK, getting closer. This is wierd. I get the following error:
System.Data.OleDb.OleDbException: Invalid object Name 'SYSDRVBY'.
SYSDRVBY is the name of my table. I don't get it (I took out the underscore)....
-
Feb 3rd, 2004, 06:14 PM
#6
Thread Starter
Fanatic Member
OK, getting closer. This is wierd. I get the following error:
System.Data.OleDb.OleDbException: Invalid object Name 'SYSDRVBY'.
SYSDRVBY is the name of my table. I don't get it (I took out the underscore)....
-
Feb 4th, 2004, 11:58 AM
#7
Thread Starter
Fanatic Member
OK I got it....Thanks!
Code:
string sconn;
string insertCommand;
string to = tWhoTo.Text;
string from = tWhoBy.Text;
string dt = tDate.Text;
string comments = tRequestMemo.Text;
sconn = "Initial Catalog=DrvBy;Data Source=DOGFISH;Integrated Security=SSPI;";
insertCommand = "Insert into SYSDRVBY (WhoFrom, WhoTo, dt, Comments) values('" + from + "','" + to + "','" + dt + "','" + comments + "')";
SqlConnection sqlconn = new SqlConnection(sconn);
//OleDbConnection conn = new OleDbConnection(sconn);
SqlCommand sqlComm = new SqlCommand(insertCommand,sqlconn);
//OleDbCommand cmd = new OleDbCommand(insertCommand,conn);
sqlconn.Open();
sqlComm.ExecuteNonQuery();
sqlconn.Close();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|