Latest developer linksBookmark and Share
 
HomeThis WeekTop MonthTop AlltimeSearchRegisterFAQ
  
 
Submit Your Link
Please login to submit your Link
 

SET IDENTITY_INSERT and SqlCeResultSet

Posted: Jan/22/2011   By: nikhil   Points:15   Category: .NET  - ASP.Net    Views:165   Vote Up (0)   Vote Down (0)    
Hello,

I'm trying to bulk insert data from Sql Server to Sql Server Compact 3.5, using SqlCeResultSet.
But I'm having trubles trying to insert data in a table that has a Identity column.
It seams that for some reason SqlCeResultSet doesn't honor the SET IDENTITY_INSERT option.
Here some source:

 

SqlCeConnection cn = new SqlCeConnection("Data Source=Database1.sdf");
SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = cn;
cn.Open();
cmd.CommandText =
"SET IDENTITY_INSERT table1 ON";
cmd.ExecuteNonQuery();
cmd.CommandText =
"SELECT * FROM table1";
SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable);
SqlCeUpdatableRecord rec = rs.CreateRecord();
rec[
"id"] = 2;
rec[
"description"] = "hello";
rec[
"code"] = 5;
rs.Insert(rec);
rs.Close();
cmd.CommandText =
"SET IDENTITY_INSERT table1 OFF";
cmd.ExecuteNonQuery();
cn.Close();





But this actually works:

 

SqlCeConnection cn = new SqlCeConnection("Data Source=Database1.sdf");
SqlCeCommand cmd = new SqlCeCommandView Complete Post


Comments:
Be the first to comment this post.
 
Post Comment
Please login to post your comment
More Related Resources

DataGrid ItemsSource=SqlCeResultSet only display header but no data

  

Im using the V4.0 DataGrid and set the ItemsSource bind to a V3.5 SP2 SqlCeResultSet. After I retrieved and set the SqlCeResultSet property. The DataGrid display the correct column header, and expanded the correct number of rows. But the data rows are all blanks.

The debug output reported this error for each columns:

System.Windows.Data Error: 40 : BindingExpression path error: 'Col1' property not found on 'object' ''RowView' (HashCode=4276224)'. BindingExpression:Path=Col1; DataItem='RowView' (HashCode=4276224); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

Is there any known issues between the DataGrid and SqlCeResultSet? This works with the WindForm.DataGrid, but appears not working with the V4 .Net WPF DataGrid.

Thanks for advance on any recommendations on how to resolve this binding issue.


Turning Identity_Insert on from MS Access

  

This might be a question for an MS Access forum, but I couldn't find one.  I hope someone can help me.  I am having a problem with a linked SQL Server table.  Under certain conditions, I I cannot insert into a particular table.  WIthout typing out the whole eror message, it suggests that Access is trying to insert a value into an Identity column, but that isn't the case.  I am hoping that if I can run a stored procedure thru code to turned Identity_Insert of for the table, it will solve the problem.  I have a procedure on the SQL Server to do this, but don't know how to execute it from Access or even from SQL Server for that matter.


Thank you for any help and God Bless,

 

Mark A. Sam


God Bless, Mark A. Sam
 
Categories:
.NET
Java
PHP
C/C++/VC++
HTML/XML
SAP
MainFrames
Data Warehousing
Testing
MySQL
SQL Server
Oracle
Javascript/VB Script
Others
Login
 
 
 
 
 Forgot password
 Contact Us   Terms Of use   Share your knowledge