Здесь я попытался добавить данные в мою базу данных доступа с помощью C#. Теперь, когда я запускаю приложение, я получаю сообщение об ошибке «Вставить Into». Как мне теперь перейти?как ввести данные в базу данных?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Santosh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" && textBox2.Text == "" && textBox3.Text == "")
MessageBox.Show("Plz Specify the UserName & Password","ERROR",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
else if (textBox2.Text == "" && textBox3.Text == "")
MessageBox.Show("Plz Specify the Password", "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
else if (textBox3.Text == "")
MessageBox.Show("Plz RE Enter the Password", "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
else
{
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\leelakrishnan\Desktop\database1.accdb";
String uname, pass;
string id;
id = textBox1.Text;
uname = textBox2.Text;
//System.Windows.Forms.MessageBox.Show(uname);
pass = textBox3.Text;
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
int i=107;
string query = @"insert into EMPLOYEE_TABLE (ID,UserName,Password) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
//string query = "insert into LOGIN_TABLE (ID,UserName,Password) VALUES (i,'uname',' pass')";
i++;
OleDbCommand myCommand = myConnection.CreateCommand();// new OleDbCommand();
myCommand.CommandText = query;
//TODO: Review the datatypes and lengths for these parameters
OleDbParameter myParm = myCommand.Parameters.Add("@id", OleDbType.VarChar,50);
myParm.Value = textBox1.Text;
myParm = myCommand.Parameters.Add("@uname", OleDbType.VarChar, 50);
myParm.Value = textBox2.Text;
myParm = myCommand.Parameters.Add("@pass", OleDbType.VarChar, 50);
myParm.Value = textBox3.Text;
myCommand.ExecuteNonQuery();
myConnection.Close();
System.Windows.Forms.MessageBox.Show("User Account Succefully Created", "Caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
}
}
}
. Он не говорит, почему инструкция insert неверна? Я уверен, что вам нужно заменить значения в запросе с помощью @id, @uname, @pass –
@shoban вы можете помочь мне с ошибками в этом кодировании? – Beginner
@Austin Это ошибка «Ошибка синтаксиса в инструкции INSERT INTO». – Beginner