SQLCE下载表格本地添加记录对于自动编号主键的处理
try
{
mycon = new SqlCeConnection("Data Source=MobileService.sdf");
mycon.Open();
SqlCeCommand mycom = mycon.CreateCommand();
mycom.CommandText = "select count(ID) from table1";
int num=(int)mycom.ExecuteScalar()+1;
mycom.CommandText = " ALTER TABLE table1 ALTER COLUMN ID IDENTITY (" + num.ToString() + ",1)";
mycom.ExecuteNonQuery();
mycom.CommandText = "insert into table1 (Tname,Tadd,Temail,Tqq) values ('"+name+"','"+add+"','"+mail+"','"+qq+"')";
mycom.ExecuteNonQuery();
MessageBox.Show("Insert OK");
mycon.Close();
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.ToString());
}
finally { mycon.Close(); }