×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

@

都是这雨下的,偶忘记了啥?谢谢!

本文发表在 rolia.net 枫下论坛连接是对的, 权限也是有的, DATASET里面的记录也对, 就是最后dp.Update(ds,"phone_address"); 不做。
今天偶漏了什么了?@@


System.Data.SqlClient.SqlConnection form3Con=new System.Data.SqlClient.SqlConnection();
form3Con.ConnectionString=.............................;

System.Data.SqlClient.SqlDataAdapter dp=new System.Data.SqlClient.SqlDataAdapter("select * from phone_address",form3Con);
System.Data.SqlClient.SqlCommandBuilder db=new System.Data.SqlClient.SqlCommandBuilder(dp);
form3Con.Open();
System.Data.DataSet ds=new DataSet( );
dp.Fill(ds,"phone_address");
System.Data.SqlClient.SqlCommand cmd=new System.Data.SqlClient.SqlCommand("INSERT INTO phone_address (PhoneNumber, Name, Street, City,State, PostCode) "+
"Values (@PhoneNumber, @Name, @Street, @City,@State, @PostCode)",form3Con);

cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PhoneNumber", SqlDbType.NVarChar, 14,"PhoneNumer"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", SqlDbType.NVarChar, 30,"Name"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Street", SqlDbType.NVarChar, 30,"Street"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", SqlDbType.NVarChar, 20, "City"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@State", SqlDbType.NChar, 20, "State"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostCode", SqlDbType.NChar, 7, "PostCode"));

cmd.Parameters["@PhoneNumber"].Value=record2.c_PhoneNumber;
cmd.Parameters["@Name"].Value=record2.c_Name;
cmd.Parameters["@Street"].Value=record2.c_Street;
cmd.Parameters["@City"].Value=record2.c_City;
cmd.Parameters["@State"].Value=record2.c_State;
cmd.Parameters["@PostCode"].Value=record2.c_PostCode;
dp.InsertCommand=cmd;

dp.Update(ds,"phone_address");更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / 都是这雨下的,偶忘记了啥?谢谢!
    本文发表在 rolia.net 枫下论坛连接是对的, 权限也是有的, DATASET里面的记录也对, 就是最后dp.Update(ds,"phone_address"); 不做。
    今天偶漏了什么了?@@


    System.Data.SqlClient.SqlConnection form3Con=new System.Data.SqlClient.SqlConnection();
    form3Con.ConnectionString=.............................;

    System.Data.SqlClient.SqlDataAdapter dp=new System.Data.SqlClient.SqlDataAdapter("select * from phone_address",form3Con);
    System.Data.SqlClient.SqlCommandBuilder db=new System.Data.SqlClient.SqlCommandBuilder(dp);
    form3Con.Open();
    System.Data.DataSet ds=new DataSet( );
    dp.Fill(ds,"phone_address");
    System.Data.SqlClient.SqlCommand cmd=new System.Data.SqlClient.SqlCommand("INSERT INTO phone_address (PhoneNumber, Name, Street, City,State, PostCode) "+
    "Values (@PhoneNumber, @Name, @Street, @City,@State, @PostCode)",form3Con);

    cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PhoneNumber", SqlDbType.NVarChar, 14,"PhoneNumer"));
    cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", SqlDbType.NVarChar, 30,"Name"));
    cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Street", SqlDbType.NVarChar, 30,"Street"));
    cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", SqlDbType.NVarChar, 20, "City"));
    cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@State", SqlDbType.NChar, 20, "State"));
    cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostCode", SqlDbType.NChar, 7, "PostCode"));

    cmd.Parameters["@PhoneNumber"].Value=record2.c_PhoneNumber;
    cmd.Parameters["@Name"].Value=record2.c_Name;
    cmd.Parameters["@Street"].Value=record2.c_Street;
    cmd.Parameters["@City"].Value=record2.c_City;
    cmd.Parameters["@State"].Value=record2.c_State;
    cmd.Parameters["@PostCode"].Value=record2.c_PostCode;
    dp.InsertCommand=cmd;

    dp.Update(ds,"phone_address");更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 大虾小虾看热闹的, 往这里瞅瞅 》》》
    • 你忘了告诉他要干什么:). DataSet每条记录有版本,你调用dp.Update时它会检查记录版本,然后他发现没有记录的版本是新插入的,就不会调用Insert command。Dataset 刚fill 完所有记录版本是original。
      • 车牌考了没有?
        • Nope. 教练拖拖拉拉.
      • 谢谢。 :))