Thanks everyone for your responses,I managed to fix my code, now everything is fine. :-D
katlegoM
Posts
-
Please help me here, I need to insert data from datagridview to ms access table, and I keep getting an error that says the insert into statement contains the following unknown field name : 'Username',please help me fix this.thanks -
Please help me here, I need to insert data from datagridview to ms access table, and I keep getting an error that says the insert into statement contains the following unknown field name : 'Username',please help me fix this.thanksAlright thank you Dave I will.
-
Please help me here, I need to insert data from datagridview to ms access table, and I keep getting an error that says the insert into statement contains the following unknown field name : 'Username',please help me fix this.thanksusing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; namespace EmployeeAttendanceRegister { public partial class SignIN : Form { public SignIN() { InitializeComponent(); } public OleDbConnection GetsqlCon() { string connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/game/Desktop/3rd year/2nd Semester/INYM 328/EmployeeAttendanceRegister/EmployeeAttendanceRegister/EmployeeAttendanceRegister.accdb"; OleDbConnection mycon = new OleDbConnection(connstring); mycon.Open(); return mycon; } public void getComm(string connstring1) { OleDbConnection sqlcon = this.GetsqlCon(); OleDbCommand sqlcomm = new OleDbCommand(connstring1, sqlcon); sqlcomm.ExecuteNonQuery(); sqlcomm.Dispose(); sqlcon.Close(); sqlcon.Dispose(); } private void button1_Click(object sender, EventArgs e) { try { string col1 = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string col2 = dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string col3 = dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string col4 = dataGridView1[3, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string col5 = dataGridView1[4, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string col6 = dataGridView1[5, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string col7 = dataGridView1[6, dataGridView1.CurrentCell.RowIndex].Value.ToString(); string insert_sql = "INSERT INTO Attendance(Username,Lastname,Firstname,Cellnumber,Officenumber,DepartmentName,Passwrd) VALUES('" + col1 + "','" + col2 + "','" + col3 + "','" + col4 + "','" + col5 + "','" + col6 + "','" + col7 + "')"; this.getComm(insert_sql); } catch (Exception ex) { MessageBox.Show(ex.Message); } }