Advertisement
Purianite

Untitled

Mar 12th, 2012
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. public void addRecord()
  2.         {
  3.             string connectString =
  4.               "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =mmodb.accdb";
  5.  
  6.             OleDbConnection myConnection = new OleDbConnection(connectString);
  7.  
  8.             //Add variables from fields here
  9.  
  10.             string insertSQL
  11.                 = "INSERT INTO PLAYER_TBL "
  12.                 + "(LASTNAME, FIRSTNAME, ALIAS, STREET, CITY, STATE, PHONE, EMAIL) "
  13.                 + "VALUES (@LastName, @FirstName, @Alias, @Street, @City, @State, @Phone, @Email)";
  14.  
  15.             OleDbCommand insertCmd = new OleDbCommand(insertSQL, myConnection);
  16.  
  17.             insertCmd.Parameters.AddWithValue("@LASTNAME", LastName);
  18.             insertCmd.Parameters.AddWithValue("@FIRSTNAME", FirstName);
  19.             insertCmd.Parameters.AddWithValue("@ALIAS", Alias);
  20.             insertCmd.Parameters.AddWithValue("@STREET", Street);
  21.             insertCmd.Parameters.AddWithValue("@CITY", City);
  22.             insertCmd.Parameters.AddWithValue("@STATE", State);
  23.             insertCmd.Parameters.AddWithValue("@PHONE", Phone);
  24.             insertCmd.Parameters.AddWithValue("@EMAIL", Email);
  25.  
  26.             try
  27.             {
  28.                 myConnection.Open();
  29.                 insertCmd.ExecuteNonQuery();
  30.                 myConnection.Close();
  31.             }
  32.             catch (Exception err)
  33.             {
  34.                 myConnection.Close();
  35.                 MessageBox.Show(err.Message);
  36.             }
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement