Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: How do I insert and update


Message #1 by "charles baldo" <charlesbaldo@h...> on Thu, 17 May 2001 18:15:20
I am trying to insert records into a database. I have been given the 

following code by quite a few friends



<script runat="server">

void Page_Load(Object sender, EventArgs e) {

string mdbPath = Server.MapPath("\\Northwind")+"\\Northwind.mdb";

ADOConnection adoConn = new ADOConnection("DRIVER={Microsoft Access Driver 

(*.mdb)}; DBQ=" +  mdbPath); 

    

// insert a record

string sqlString = "INSERT INTO Categories (CategoryName,Description) " +

   "VALUES ('Vegan','Non-Dairy Dishes')"

ADOCommand adoCmd1 = new ADOCommand(sqlString,adoConn);

adoConn.Open();

adoCmd1.ExecuteNonQuery();

adoConn.Close();

}



</script>



When I run this I get an error that the ODBC driver does not exist. I know 

it does because I use it for other things.



This seems like it is using a recordset sytle update. Should this be using 

a dataset in some fashion? Can anyone please help



Chuck
Message #2 by "Alex Lowe" <alowe@s...> on Tue, 29 May 2001 04:39:33
Try changing your connection string to something like this:



strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" +

                "Data Source=" + mdbPath + ";" +

                "Persist Security Info=False;";



You do not need to use a dataset to insert data into a database.



hth,

Alex

http://www.asp-grandrapids.net

webmaster@a...



> I am trying to insert records into a database. I have been given the 

> following code by quite a few friends

> 

> <script runat="server">

> void Page_Load(Object sender, EventArgs e) {

> string mdbPath = Server.MapPath("\\Northwind")+"\\Northwind.mdb";

> ADOConnection adoConn = new ADOConnection("DRIVER={Microsoft Access 

Driver 

> (*.mdb)}; DBQ=" +  mdbPath); 

>     

> // insert a record

> string sqlString = "INSERT INTO Categories (CategoryName,Description) " +

>    "VALUES ('Vegan','Non-Dairy Dishes')"

> ADOCommand adoCmd1 = new ADOCommand(sqlString,adoConn);

> adoConn.Open();

> adoCmd1.ExecuteNonQuery();

> adoConn.Close();

> }

> 

> </script>

> 

> When I run this I get an error that the ODBC driver does not exist. I 

know 

> it does because I use it for other things.

> 

> This seems like it is using a recordset sytle update. Should this be 

using 

> a dataset in some fashion? Can anyone please help

> 


  Return to Index