本文介绍了我在INSERT中声明错误消息=语法错误。有人请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把数据插入到访问数据库中



我的代码:



使用System;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;

使用System.Data.OleDb;

使用System.Drawing;

使用System.Linq;

使用System.Text;

使用System.Windows.Forms;



命名空间激活器

{

公共部分类Form1:表格

{

public Form1()

{

InitializeComponent();

}

OleDbConnection connect = new OleDbConnection();

private void button2_Click(object sender,EventArgs e)

{

this.Close();



}



private void button1_Click(object sender,EventArgs e)

{

connect.ConnectionString = @Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ data \ test.accdb;

Jet OLEDB:Database Password = nif6914;;



string blinker = textBox1.Text;

string blinker2 = textBox2.Text;

connect.Open();

OleDbCommand cmd = new OleDbCommand(INSERT into Z_UL_Data(UL_RDate,UL_RActivation)+value(@ blinker,@ blinker2),connect);

if(connect) .State == ConnectionState.Open)

{

cmd.Parameters.Add(@ blinker,OleDbType.Char,20).Value = blinker;

cmd.Parameters.Add(@ blinker2,OleDbType.Char,20).Value = blinker2;

尝试

{

cmd.ExecuteNonQuery();

MessageBox.Show(更新Sucsessfull);

textBox1.Text =;

textBox2.Text =;

connect.Close();

}

catch(Exception exp)

{

MessageBox.Show(Error+ exp);

connect.Close();

}





}

else

{

MessageBox.Show(连接失败);

connect.Close();



}





}

}



}



我尝试了什么:



我需要将我的插入更改为字符串

解决方案



i am tying to insert data into accesss database

my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace activator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection connect = new OleDbConnection();
private void button2_Click(object sender, EventArgs e)
{
this.Close();

}

private void button1_Click(object sender, EventArgs e)
{
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\data\test.accdb;
Jet OLEDB:Database Password=nif6914;";

string blinker = textBox1.Text;
string blinker2 = textBox2.Text;
connect.Open();
OleDbCommand cmd = new OleDbCommand("INSERT into Z_UL_Data(UL_RDate,UL_RActivation)" + "value(@blinker,@blinker2)", connect);
if (connect.State == ConnectionState.Open)
{
cmd.Parameters.Add("@blinker", OleDbType.Char, 20).Value = blinker;
cmd.Parameters.Add("@blinker2", OleDbType.Char, 20).Value = blinker2;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Update Sucsessfull");
textBox1.Text = "";
textBox2.Text = "";
connect.Close();
}
catch (Exception exp)
{
MessageBox.Show("Error" + exp);
connect.Close();
}


}
else
{
MessageBox.Show("Connection Failled");
connect.Close();

}


}
}

}

What I have tried:

do i need to change my insert into string

解决方案



这篇关于我在INSERT中声明错误消息=语法错误。有人请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 09:04