当前位置: 代码迷 >> ASP.NET >> adapter.Update的有关问题?
  详细解决方案

adapter.Update的有关问题?

热度:794   发布时间:2013-02-26 00:00:00.0
adapter.Update的问题???
小弟初学ASP.NET请各位高手帮忙??
adapter.Updat怎么不上传数据??adapter.Updat能像这样用吗??如果不是该怎么用???

upconnection.ConnectionString   =   ConfigurationManager.ConnectionStrings[ "webConnectionString "].ConnectionString;

upcommand   =   new   SqlCommand();
                        upcommand.CommandText   =   "UPDATE   [number]   SET   [number]   =   222   ";
                        upcommand.CommandType   =   CommandType.Text;
                        upcommand.Connection   =   upconnection;

                        myconnection.Open();
                                               
                        myadapter   =   new   SqlDataAdapter();
                        myadapter.SelectCommand   =   mycommand;
                        myadapter.UpdateCommand   =   upcommand;
                        myadapter.Fill(mytable);
                        myadapter.Update(mytable);

------解决方案--------------------------------------------------------
上传数据 不用整个记录都返回回来 只要知道操作成功的记录数就行了

myconnection.open();
upcommand = new SqlCommand();
";
upcommand.Connection = upconnection;??你是open的myconnection撒 怎么出来了个upconnection

upcommand.Connection=myconnection.Connection

int flag = upcommand.ExecuteNonQuery();//无记录时是 “-1”
try
{
upcommand.CommandText = "UPDATE [number] SET [number] = 222
int flag = myconnection.ExecuteNonQuery();
if(flag != -1)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
return false;
}

------解决方案--------------------------------------------------------
这里边SQL 语句不对
并没有SQL Parameter参数
这样就不能执行你的SQL语句
---------------------------
SqlConnection myConnection = new SqlConnection( "server=(local)\\SQLExpress;Integrated Security=SSPI;database=northwind ");
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter( "Select * from Region ", myConnection);
SqlParameter workParam = null;

// Restore database to it 's original condition so sample will work correctly.
Cleanup();

// Build the insert Command
mySqlDataAdapter.InsertCommand = new SqlCommand( "Insert into Region (RegionID, RegionDescription) VALUES (@RegionID, @RegionDescription) ", myConnection);

workParam = mySqlDataAdapter.InsertCommand.Parameters.Add( "@RegionID ", SqlDbType.Int);
workParam.SourceColumn = "RegionID ";
workParam.SourceVersion = DataRowVersion.Current;

workParam = mySqlDataAdapter.InsertCommand.Parameters.Add( "@RegionDescription ", SqlDbType.NChar, 50);
  相关解决方案