Results 1 to 7 of 7

Thread: Write to SQL db

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    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); 
    			
    		
    		}

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    you aren't executing the query. Try the code below
    VB Code:
    1. private void bSubmit_Click(object sender, System.EventArgs e)
    2. {
    3.    string sconn;
    4.    string insertCommand;
    5.    string to = tWhoTo.Text; //Request.Form("fDriveBy").(tWhoTo);
    6.            
    7.    sconn = "Provider=SQLOLEDB;Data Source=DOGFISH;InitialCatalog=DrvBy;Integrated Security=SSPI;";
    8.    insertCommand = "Insert into SYS_DRVBY(WhoFrom, WhoTo, dt, Comments) values('" + to + "','" + to + "','" + "11/01/2001" + "','" + "this is a test" + "')";
    9.    OleDbConnection conn = new OleDbConnection(sconn);
    10.    OleDbCommand cmd = new OleDbCommand(insertCommand,conn);
    11.  
    12.     conn.Open();
    13.     cmd.ExecuteNonQuery();
    14.     conn.Close();      
    15. }
    Last edited by Memnoch1207; Feb 3rd, 2004 at 05:55 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    I get this error:

    No overload for method 'ExecuteNonQuery' takes '2' arguments

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    I changed it.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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)....

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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)....

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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
  •  



Click Here to Expand Forum to Full Width