Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //C# Access and @@Identity
- string query = "Insert Into Categories (CategoryName) Values (?)";
- string query2 = "Select @@Identity";
- int ID;
- string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Northwind.mdb";
- using (OleDbConnection conn = new OleDbConnection(connect))
- {
- using (OleDbCommand cmd = new OleDbCommand(query, conn))
- {
- cmd.Parameters.AddWithValue("", Category.Text);
- conn.Open();
- cmd.ExecuteNonQuery();
- cmd.CommandText = query2;
- ID = (int)cmd.ExecuteScalar();
- }
- }
- //C# DataSource controls
- protected void AccessDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
- {
- string query = "SELECT @@IDENTITY";
- OleDbCommand cmd = new OleDbCommand(query, (OleDbConnection)e.Command.Connection);
- int newid = (int)cmd.ExecuteScalar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement