首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

datagrid的有关问题

2012-02-13 
datagrid的问题1,我怎么设置或者写代码才可以实现,当我选择其中一行的时候,这一行用户才可以编辑,否则用户

datagrid的问题
1,我怎么设置或者写代码才可以实现,当我选择其中一行的时候,这一行用户才可以编辑,否则用户不可以进行编辑
2,datagrid和dataset的datatable绑定的,我的datatable中的字段默认值都是dbnull,我想在编辑完单元格以后,离开的时候判断一下,如果内容不是dbnull的时候,也不是数字的时候,要谈出对话框,然后焦点在该单元格上

[解决办法]
//添加按钮中代码:
private void button2_Click(object sender, System.EventArgs e)
{
if(this.dataGrid1.DataSource == null){
return;
}
this._ds.Tables[0].Rows.Add(this._ds.Tables[0].NewRow());
}
//更新按钮中代码
private void button4_Click(object sender, System.EventArgs e)
{
this._sda.InsertCommand = new System.Data.SqlClient.SqlCommand
( "insert into books values(@ID,@Type,@Name,@Author,@Price,@Cover,@TotalNum,@SaleNum) ",
this._sconn);

this._sda.InsertCommand.Parameters.Add( "@ID ",System.Data.SqlDbType.Int);
this._sda.InsertCommand.Parameters[ "@ID "].SourceColumn = "ID ";
this._sda.InsertCommand.Parameters[ "@ID "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@Type ",System.Data.SqlDbType.VarChar);
this._sda.InsertCommand.Parameters[ "@Type "].SourceColumn = "Type ";
this._sda.InsertCommand.Parameters[ "@Type "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@Name ",System.Data.SqlDbType.VarChar);
this._sda.InsertCommand.Parameters[ "@Name "].SourceColumn = "Name ";
this._sda.InsertCommand.Parameters[ "@Name "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@Author ",System.Data.SqlDbType.VarChar);
this._sda.InsertCommand.Parameters[ "@Author "].SourceColumn = "Author ";
this._sda.InsertCommand.Parameters[ "@Author "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@Price ",System.Data.SqlDbType.Decimal);
this._sda.InsertCommand.Parameters[ "@Price "].SourceColumn = "Price ";
this._sda.InsertCommand.Parameters[ "@Price "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@Cover ",System.Data.SqlDbType.VarChar);
this._sda.InsertCommand.Parameters[ "@Cover "].SourceColumn = "Cover ";
this._sda.InsertCommand.Parameters[ "@Cover "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@TotalNum ",System.Data.SqlDbType.BigInt);
this._sda.InsertCommand.Parameters[ "@TotalNum "].SourceColumn = "TotalNum ";
this._sda.InsertCommand.Parameters[ "@TotalNum "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.InsertCommand.Parameters.Add( "@SaleNum ",System.Data.SqlDbType.BigInt);
this._sda.InsertCommand.Parameters[ "@SaleNum "].SourceColumn = "SaleNum ";
this._sda.InsertCommand.Parameters[ "@SaleNum "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand = new System.Data.SqlClient.SqlCommand
( "update books set ID=@ID,Type=@Type,Name=@Name,Author=@Author,Price=@Price,Cover=@Cover,TotalNum=@TotalNum,SaleNum=@SaleNum where ID=@oID ",
this._sconn);

this._sda.UpdateCommand.Parameters.Add( "@ID ",System.Data.SqlDbType.Int);
this._sda.UpdateCommand.Parameters[ "@ID "].SourceColumn = "ID ";
this._sda.UpdateCommand.Parameters[ "@ID "].SourceVersion = System.Data.DataRowVersion.Current;



this._sda.UpdateCommand.Parameters.Add( "@Type ",System.Data.SqlDbType.VarChar);
this._sda.UpdateCommand.Parameters[ "@Type "].SourceColumn = "Type ";
this._sda.UpdateCommand.Parameters[ "@Type "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@Name ",System.Data.SqlDbType.VarChar);
this._sda.UpdateCommand.Parameters[ "@Name "].SourceColumn = "Name ";
this._sda.UpdateCommand.Parameters[ "@Name "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@Author ",System.Data.SqlDbType.VarChar);
this._sda.UpdateCommand.Parameters[ "@Author "].SourceColumn = "Author ";
this._sda.UpdateCommand.Parameters[ "@Author "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@Price ",System.Data.SqlDbType.Decimal);
this._sda.UpdateCommand.Parameters[ "@Price "].SourceColumn = "Price ";
this._sda.UpdateCommand.Parameters[ "@Price "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@Cover ",System.Data.SqlDbType.VarChar);
this._sda.UpdateCommand.Parameters[ "@Cover "].SourceColumn = "Cover ";
this._sda.UpdateCommand.Parameters[ "@Cover "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@TotalNum ",System.Data.SqlDbType.BigInt);
this._sda.UpdateCommand.Parameters[ "@TotalNum "].SourceColumn = "TotalNum ";
this._sda.UpdateCommand.Parameters[ "@TotalNum "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@SaleNum ",System.Data.SqlDbType.BigInt);
this._sda.UpdateCommand.Parameters[ "@SaleNum "].SourceColumn = "SaleNum ";
this._sda.UpdateCommand.Parameters[ "@SaleNum "].SourceVersion = System.Data.DataRowVersion.Current;

this._sda.UpdateCommand.Parameters.Add( "@oID ",System.Data.SqlDbType.Int);
this._sda.UpdateCommand.Parameters[ "@oID "].SourceColumn = "ID ";
this._sda.UpdateCommand.Parameters[ "@oID "].SourceVersion = System.Data.DataRowVersion.Original;

this._sda.DeleteCommand = new System.Data.SqlClient.SqlCommand( "delete books where ID=@ID ",this._sconn);

this._sda.DeleteCommand.Parameters.Add( "@ID ",System.Data.SqlDbType.Int);
this._sda.DeleteCommand.Parameters[ "@ID "].SourceColumn = "ID ";
this._sda.DeleteCommand.Parameters[ "@ID "].SourceVersion = System.Data.DataRowVersion.Original;

if(this._ds == null){
return;
}
try
{
this._sda.Update(this._ds);
}
catch(Exception ex){
MessageBox.Show(ex.ToString());
}
}

热点排行