对了第二个问题它指的错误是这行 myCmd.ExecuteNonQuery();
解决方案 »
- C# Socket异步编程,重启服务器,客户端连接不上,怎么办?
- 认算SHA1哈希值的问题?在线等.
- 如何将ComponentOne Chart中的ValueLabel的text以竖着的形式显示?
- 有谁知道,加密过的SQL文件怎么解密啊?
- 请问函数参数中Object& Param.应该传什么类型数据,如何传。
- 请问 DataReader 如何获得记录数?????(
- 如何在C#类中编写执行某软件的代码。
- 急,急,急~!!如何在C#中将汉字转换成2进制代码并将2进制代码存放在一个数组里面
- 请问如何在程序中实现关机操作?
- 如何设置Toolbar中ToolBarButton上的图片?
- 急问!!! 来者有分!!!!
- 把信誉分丢了好多,怎样才能长起来,长20的信誉分要回答多少个贴子
OleDbConnection myConn = new OleDbConnection(@"Integrated Security=SSPI;Packet Size=4096;Data Source=FAN;Tag with column collation when possible=False;Initial Catalog=Market;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=FAN;Use Encryption for Data=False");
myConn.Open();
string strInsert = " INSERT INTO Orderz( orderid,goodsname,customerid,quantity,ordersum,orderdate ) VALUES('"
+ txtOI.Text +"','"
+ txtGS.Text +"','"
+ txtCI.Text +"','"
+ txtQ.Text +"','"+txtOS.Text+"','"+txtOD.Text+"')";
//MessageBox.Show(strInsert);
OleDbCommand myCmd = new OleDbCommand(strInsert,myConn);
myCmd.ExecuteNonQuery();
myConn.Close();
MessageBox.Show("成功添加图书" + txtOI.Text + "的信息,请点击‘重新加载数据’以显示信息!","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
//信息合法性检查
if (textBox7.Text=="" || txtCI.Text =="" || txtGS.Text=="" || txtOS.Text=="" || txtQ.Text=="")
{
MessageBox.Show("提交的信息不完全!","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
return;
}
try
{
//this.dataGrid1.EndInit();
this.mybind.EndCurrentEdit();
this.ccDA.Update(this.ccDS,"Orderz");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
public string FillMainDS_OLEDB(string Connection,string Command,string TableName)
{
//自定义函数
//功能:采用OLEDB方式连接,将Command命令通过Connection查询出结果,填充到MainDataSet中的TableName表中
//输入:Connection数据连接串,Command SQL命令,TableName MainDataSet中的表名
//输出:直接修改MainDataSet。
//返回:提示信息。
try
{
OleDbConnection conn = new OleDbConnection(Connection);
conn.Open();
OleDbCommand comm = new OleDbCommand(Command,conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
adapter.Fill(MainDataSet,TableName);
conn.Close();
return "成功。";
}
catch(Exception e3)
{
return "失败。"+ e3.ToString ( );
}
}
public string FillMainDS_SQL (string Connection,string Command,string TableName)
{
//自定义函数
//功能:采用SQL Client方式连接,将Command命令通过Connection查询出结果,填充到MainDataSet中的TableName表中
//输入:Connection数据连接串,Command SQL命令,TableName MainDataSet中的表名
//输出:直接修改MainDataSet。
//返回:提示信息。
try
{
SqlConnection myConn = new SqlConnection ( Connection ) ;
myConn.Open ( ) ;
SqlDataAdapter myAdapter = new SqlDataAdapter ( Command , myConn ) ;
myAdapter.Fill (MainDataSet,TableName) ;
myConn.Close ( ) ;
return "成功。";
}
catch ( Exception e4)
{
return "失败。"+ e4.ToString ( );
}
}
public string ExeSQL_OLEDB(string Connection,string Command)
{
//自定义函数
//功能:执行SQL命令,通过Oledb连接
//输入:Connection数据连接串,Command SQL命令
//输出:直接修改数据库
//返回:提示信息。
try
{
OleDbConnection conn = new OleDbConnection(Connection);
conn.Open();
OleDbCommand comm = new OleDbCommand(Command,conn);
comm.ExecuteNonQuery();
conn.Close();
return "成功。";
}
catch(Exception e6){return "失败。"+e6.ToString();}
}
public string ExeSQL_SQL(string Connection,string Command)
{
//自定义函数
//功能:执行SQL命令,通过SQL Client连接
//输入:Connection数据连接串,Command SQL命令
//输出:直接修改数据库
//返回:提示信息。
try
{
SqlConnection myConn = new SqlConnection ( Connection ) ;
myConn.Open ( ) ;
SqlCommand myCom=new SqlCommand(Command,myConn);
myCom.ExecuteNonQuery ( ) ;
myConn.Close ( ) ;
return "成功。";
}
catch(Exception e7){return "失败。"+e7.ToString();}
}
sql连接方式
data source=;initial catalog=;password=;persist security info=True;user id=;workstation id=;packet size=OLEDB连接方式
informix的
Provider=Ifxoledbc.2;password=;User ID=;Data Source=@;Persist Security Info=true
1、你的数据库联接写的太负杂了,没那么恐怖;
2、insert的时候不是出错么,你用try...catch把错误抓出来;
3、按下update出现 未将对象引用设置到对象实例.(查查有没有什么对象没有new)