I'm trying to save a transaction to a transaction table in MS database. I get the following error.
System.Data.OleDb.OleDbException
HResult=0x80040E14
Message=Syntax error (missing operator) in query expression '6GTPY'.
Source=App_Web_zys52can
StackTrace:
at _Default.SaveTransaction() in C:\Users\ben-b\Documents\NewBlackCatDatabase\NewBlackCatPCDatabase\Inventory.aspx.cs:line 63
at _Default.Button4_Click(Object sender, EventArgs e) in C:\Users\ben-b\Documents\NewBlackCatDatabase\NewBlackCatPCDatabase\Inventory.aspx.cs:line 44
This exception was originally thrown at this call stack:
[External Code]
_Default.SaveTransaction() in Inventory.aspx.cs
_Default.Button4_Click(object, System.EventArgs) in Inventory.aspx.cs
[External Code]
Webform Screenshot -
The code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection connection = DatabaseConnection.ConnectCurrentDatabase();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Redirect("CurrentStock.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void Button4_Click(object sender, EventArgs e)
{
SaveTransaction();
GridView1.DataBind();
DetailsView3.DataBind();
}
void SaveTransaction()
{
string Transaction = TextBox4.Text;
string ItemTypeCode = TextBox3.Text;
string StockIn = TextBox1.Text;
string StockOut = TextBox2.Text;
string LoggedinUserName = LoginName1.Page.User.Identity.Name;
connection.Open();
String myQuery = "Insert into TransactionTable (ItemTypeCode, Transactions, StockIn, StockOut, RecordedBy)" +
" Values ( " + ItemTypeCode + ",' " + Transaction + ",'" + StockIn + ",'" + StockOut + ",'" + LoggedinUserName + "')";
OleDbCommand command = new OleDbCommand(myQuery, connection);
command.ExecuteNonQuery();
connection.Close();
}
}
The database:
Will really appreciate the help as I've been trying to resolve this for 5 weeks now.