SQL=“Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values('"+1016+"'﹐'"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+jcy+"','"+68764+"','"+657646+"','"+jcy+"',0)”;
调试欢乐多
現在應該可以了
好象还是不行,真是麻烦你了!
我剛才做了個試驗
string strcomm1="insert into Student(Studentid,Grade,LastName,FirstName)Values('100','1','1','1')";
沒什么錯﹐很好啊
{
try
{
DataSet ds=new DataSet();
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
SqlDataAdapter adp=new SqlDataAdapter(myExecuteQuery, myConnection);
adp.Fill(ds);
}
catch(Exception Ex)
{
throw Ex;
}
}
你的这段代码我考过来用
SqlDataAdapter adp=new SqlDataAdapter(myExecuteQuery, myConnection);
出错,告诉我myConnection类型不对!
你好象引用了using System.Data.SqlClient;
不用引用这个类能解决吗?
public void CreateMyOleDbCommand(string myExecuteQuery, string myConnectionString)
{
try
{
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand(myExecuteQuery, myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
catch(Exception Ex)
{
throw Ex;
}
}
老是出错呀!一执行到myCommand.ExecuteNonQuery();就出错!是不是C#有什么BUG呀那位高手在帮着看看!我在线等!!!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;namespace Contest
{
/// <summary>
/// MainForm 的摘要说明。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private OleDbConnection cnn=pool.getConnection();
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage Ex1;
private System.Windows.Forms.TabPage Ex3;
private System.Windows.Forms.TextBox vSQL;
private System.Windows.Forms.TextBox vInnerex;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public MainForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.Ex1 = new System.Windows.Forms.TabPage();
this.vSQL = new System.Windows.Forms.TextBox();
this.Ex3 = new System.Windows.Forms.TabPage();
this.vInnerex = new System.Windows.Forms.TextBox();
this.tabControl1.SuspendLayout();
this.Ex1.SuspendLayout();
this.Ex3.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 256);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 40);
this.button1.TabIndex = 0;
this.button1.Text = "TEST";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tabControl1
//
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.Ex1,
this.Ex3});
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Top;
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(504, 248);
this.tabControl1.TabIndex = 2;
//
// Ex1
//
this.Ex1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.vSQL});
this.Ex1.Location = new System.Drawing.Point(4, 21);
this.Ex1.Name = "Ex1";
this.Ex1.Size = new System.Drawing.Size(496, 223);
this.Ex1.TabIndex = 0;
this.Ex1.Text = "SQL";
//
// vSQL
//
this.vSQL.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.vSQL.Dock = System.Windows.Forms.DockStyle.Fill;
this.vSQL.Multiline = true;
this.vSQL.Name = "vSQL";
this.vSQL.Size = new System.Drawing.Size(496, 223);
this.vSQL.TabIndex = 2;
this.vSQL.Text = "";
//
// Ex3
//
this.Ex3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.vInnerex});
this.Ex3.Location = new System.Drawing.Point(4, 21);
this.Ex3.Name = "Ex3";
this.Ex3.Size = new System.Drawing.Size(496, 223);
this.Ex3.TabIndex = 2;
this.Ex3.Text = "InerExce";
//
// vInnerex
//
this.vInnerex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.vInnerex.Dock = System.Windows.Forms.DockStyle.Fill;
this.vInnerex.Multiline = true;
this.vInnerex.Name = "vInnerex";
this.vInnerex.Size = new System.Drawing.Size(496, 223);
this.vInnerex.TabIndex = 3;
this.vInnerex.Text = "";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(504, 301);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1,
this.button1});
this.Name = "MainForm";
this.Text = "MainForm";
this.tabControl1.ResumeLayout(false);
this.Ex1.ResumeLayout(false);
this.Ex3.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion
[STAThread]
static void Main()
{
Application.Run(new MainForm());
} private void button1_Click(object sender, System.EventArgs e)
{
try
{
String ConStr="Provider = Microsoft.Jet.OLEDB.4.0;Data Source =Jcy.mdb";
String SQLStr="Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)";
this.vSQL.Text=SQLStr;
this.CreateMyOleDbCommand(SQLStr,ConStr);
}
catch
{
}
}
public void CreateMyOleDbCommand(string myExecuteQuery, string myConnectionString)
{
try
{
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
OleDbCommand myCommand = new OleDbCommand(myExecuteQuery, myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
catch(Exception Ex)
{
// throw Ex;
this.vInnerex.Text=Ex.ToString();
}
}
}
}
运行后点测试,SQL和错误会显示的
数据库可以自己按我第一次发的建立,我的ID是插入的,不是自动增加的!
在Sql Server中运行,有关键字问题
问题是在C#中运行就出现了问题呀,而且是在提交的时候出错的
————————————————————————————————————
“首先检查类型是不是匹配,如果你认为没问题,同意楼上的写的Select 格式,比如字符型药用'"+xyz+"',其他的"+xyx+",好像不是应该是其他的问题,更别说是C#的BUG......”楼上说的我试过了,还是不行“'"+xyz+"'”这样的写法有错误,这样xyz会变成变量,而不是要存入的值了
我也试过,不过也不行,返回是0,正常返回1的
没有带小数的可能!况且
"Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,MEMO,ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)"
这句SQL语句保存到一个String的变量中
——————————BILLZXH在线等回复
"Insert into SYSUSER(ID,NAME,DESCR,DEPARTMENT,PWD,RULE,CATEGORY,PHONE,FAX,[MEMO],ISGROUP) Values(1016,'jcy','jcy','jcy','jcy','jcy','jcy','68764','657646','jcy',0)"
看明白了没MEMO是ACCESS数据库的默认关键字你应该把这个字段名改了。不过不改按我的做也对。