Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Updating Access Database with User Input

AmnestyAmnesty Member Posts: 6
Ok now i'm trying to Insert more then one field into my database after users input and submit a form but im receiving errors..my code reads as

string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\DEMO1\Demographics.mdb";

OleDbConnection myConnection = new OleDbConnection( connectionString );
myConnection.Open();

string query = "INSERT INTO demographics_tbl [Last_Name], [First_Name] VALUES ('" + "LastName.Text" + "FirstName.Text""')";

Response.Write(query);

OleDbCommand myCommand = new OleDbCommand();
myCommand.CommandText = query;
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();

myConnection.Close();

But everytime I run my form and I enter in all data and submit I get an error dealing with the myCommand.ExecuteNonQuery() function.

What am I don't wrong now? Am I missing a step. Any help would be great

Thank you in Advance.

James

Comments

  • iwilld0itiwilld0it Member Posts: 1,134
    : Ok now i'm trying to Insert more then one field into my database after users input and submit a form but im receiving errors..my code reads as
    :
    : string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\DEMO1\Demographics.mdb";
    :
    : OleDbConnection myConnection = new OleDbConnection( connectionString );
    : myConnection.Open();
    :
    : string query = "INSERT INTO demographics_tbl [Last_Name], [First_Name] VALUES ('" + "LastName.Text" + "FirstName.Text""')";
    :
    : Response.Write(query);
    :
    : OleDbCommand myCommand = new OleDbCommand();
    : myCommand.CommandText = query;
    : myCommand.Connection = myConnection;
    : myCommand.ExecuteNonQuery();
    :
    : myConnection.Close();
    :
    : But everytime I run my form and I enter in all data and submit I get an error dealing with the myCommand.ExecuteNonQuery() function.
    :
    : What am I don't wrong now? Am I missing a step. Any help would be great
    :
    : Thank you in Advance.
    :
    : James
    :

    I belive you have a faulty sql statement ... insert statements are in this format ...

    [code]
    INSERT INTO TableName (col1, col2, etc) VALUES (value1, value2, etc)
    [/code]

    The parenthesis are required.
Sign In or Register to comment.