I am trying to complete a seemingly simple task that has turned into a few hours of adventure: Getting @@Identityfrom TableAdapter.Insert().
Here is my code:
protected void submitBtn_Click(object sender, EventArgs e)
{
AssetsDataSetTableAdapters.SitesTableAdapter sta = new AssetsDataSetTableAdapters.SitesTableAdapter();
int insertedID = sta.Insert(siteTxt.Text,descTxt.Text);
AssetsDataSetTableAdapters.NotesTableAdapter nta = new AssetsDataSetTableAdapters.NotesTableAdapter();
nta.Insert(notesTxt.Text, insertedID, null,null,null,null,null,null);
Response.Redirect("~/Default.aspx");
}
One answer suggests all I may need to do is change ExecuteMode. I have tried this. This causes it to GetData()stop working (because now I am returning the scalar instead of rowdata) (I need to save GetData ()). It also does not solve the problem that the insertID variable is still set to 1.
I tried to create a second one TableAdapterin TypedDataSet.XSDand set the property for this adapter to "scalar", but it still does not work with a variable that gets a value of 1.
Generated Insert Command
INSERT INTO [dbo].[Sites] ([Name], [Description]) VALUES (@Name, @Description);
SELECT Id, Name, Description FROM Sites WHERE (Id = SCOPE_IDENTITY())
" " ( Insert Update Identity).
SQL Server 2008 R2, Visual Studio 2010,.NET 4, Windows XP, .
?
/
, Visual Studio. , "", , *.XSD, SQL . - Identity. .