| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 594 人关注过本帖
标题:谁知道哪错了????
只看楼主 加入收藏
笑笑
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2006-7-8
收藏
 问题点数:0 回复次数:2 
谁知道哪错了????

我找不到错误了,谁帮我看看,谢谢了!~

private void Form1_Load(object sender, EventArgs e)
{
objSqlConnection = new SqlConnection("Integrated Security=SSPI;database =my;server=localhost;");
objSqlDataAdapter = new SqlDataAdapter("select * from Books_Details",objSqlConnection);
DataSet ds = new DataSet();
objSqlDataAdapter.Fill(ds, "Books_Details");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "Books_Details";
string insCmd = "insert into Books_Details values(@Books_Details,@Name,@Author,@Price,@Qty)";
this.objSqlDataAdapter.InsertCommand = new SqlCommand(insCmd, this.objSqlConnection);
objParam = objSqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@BookAccessCode",System.Data.SqlDbType.VarChar,4));
objParam.SourceColumn = "BookAccessCode";
objParam.SourceVersion = DataRowVersion.Current;
objParam = objSqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@Name",System.Data.SqlDbType.VarChar,10));
objParam.SourceColumn = "Name";
objParam.SourceVersion = DataRowVersion.Current;
objParam = objSqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@Author",System.Data.SqlDbType.VarChar,10));
objParam.SourceColumn = "@Author";
objParam.SourceVersion = DataRowVersion.Current;
objParam = objSqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@Price",System.Data.SqlDbType.Decimal,9));
objParam.SourceVersion = DataRowVersion.Current;
objParam.SourceColumn = "Price";
objParam = objSqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("&Qty",System.Data.SqlDbType.Int ,4));
objParam.SourceColumn = "Qty";
objParam.SourceVersion = DataRowVersion.Current;

}
private bool ValidateFields()
{
bool returnValue = true;
if (this.txtBookAccessCode.Text.Trim() == string.Empty)
{
MessageBox.Show("请提供完整的信息");
this.txtBookName.Focus();
return false;
}
else
{
//检查作者名字段有无任何数字数据
for (int i = 0; i < this.txtAuthor.Text.Length; i++)
{
if (char.IsNumber(txtAuthor.Text.ToString(), i))
{
MessageBox.Show("作者名不能是数字");
this.txtAuthor.Focus();
returnValue = false;
break;
}
}
for (int i = 0; i < this.txtPrice.Text.Length; i++)
{
if (!char.IsNumber(txtPrice.Text.ToString(), i))
{
MessageBox.Show("价格应为数字");
this.txtPrice.Focus();
returnValue = false;
break;
}
}
for (int i = 0; i < this.txtQty.Text.Length; i++)
{
if (!char.IsNumber(txtQty.Text.ToString(), i))
{
MessageBox.Show("图书数量应为数字");
this.txtQty.Focus();
returnValue = false;
break;
}

}
}
return returnValue;
}


private void btnInsertBkDt_Click(object sender, EventArgs e)
{
try
{
if (this.txtBookAccessCode.Text != string.Empty && this.txtAuthor.Text != string.Empty
&& this.txtPrice.Text != string.Empty && this.txtQty.Text != string.Empty && this.txtBookName.Text != string.Empty)
{
if (Validate())
{
DataRow objDataRow = ds.Tables["Books_Details"].NewRow();
objDataRow["BookAccessCode"] = this.txtBookAccessCode.Text;
objDataRow["Name"] = this.txtBookName.Text;
objDataRow["Author"] = this.txtAuthor.Text;
objDataRow["Price"] = this.txtPrice.Text;
objDataRow["Qty"] = this.txtQty.Text;
ds.Tables["Books_Details"].Rows.Add(objDataRow);
ds.HasChanges(DataRowState.Added);
objSqlDataAdapter.Update(ds, "Books_Details");
MessageBox.Show("图书成功入库");
this.txtBookName.Clear();
this.txtPrice.Clear();
this.txtQty.Clear();
this.txtBookAccessCode.Clear();
this.txtAuthor.Clear();
this.dataGridView1.Update();
this.txtBookName.Focus();
}
}
else if (ds.HasChanges())
{
objSqlDataAdapter.Update(ds, "Books_Details");
MessageBox.Show("已成功添加记录");

}
else
MessageBox.Show("提供完整的信息");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}

}

private void btnExit_Click(object sender, EventArgs e)
{
this.objSqlConnection.Close();
this.Close();
}
private void frmAddBooks_closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.objSqlConnection.Close();
}
}
}

搜索更多相关主题的帖子: localhost database private server 
2006-07-16 09:31
niat32214
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-7-29
收藏
得分:0 
把你的运行的时候,错误提示发来看看啊

2006-07-30 16:54
lpx
Rank: 1
等 级:新手上路
帖 子:163
专家分:0
注 册:2005-4-24
收藏
得分:0 

读别人的程序还不如自己写


我还在编程路上转悠,偶而看到一两盏灯不是为我而亮
2006-07-30 18:31
快速回复:谁知道哪错了????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025499 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved