Problemer med Insert command
Hej,jeg skal bare skrive i en database, men det er åbenbart ikke sådan lige at gøre, min kode ser ud som følger:
namespace tune {
using System;
using System.Web.UI;
using System.Data;
using System.Data.OleDb;
using System.Web.UI.WebControls;
/// <summary>
/// Summary description for indtast_resultat.
/// </summary>
public class indtast_resultat : Page {
public DataGrid dg1, dg2, dgUpd;
public Label L1;
void Page_Load(object sender, EventArgs e)
{
string strConnection, strSQL;
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = null;
OleDbDataAdapter objAdapter = null;
strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=/inetpub/wwwroot/db/bkasse.mdb";
strSQL = "SELECT * FROM login";
objConnection = new OleDbConnection(strConnection);
objAdapter = new OleDbDataAdapter(strSQL, objConnection);
objAdapter.Fill(objDataSet, "login");
dg1.DataSource = objDataSet.Tables["login"].DefaultView;
dg1.DataBind();
DataTable objTable = null;
DataRow objnewRow = null;
objTable = objDataSet.Tables["login"];
objnewRow = objTable.NewRow();
objnewRow["brugernavn"]= "osupohupt";
objnewRow["password"]= "dilliopnoer";
objnewRow["nummer"]= "22";
//objnewRow["resultat_2"]= "11";
//objnewRow["id_kampe"]="erer";
objTable.Rows.Add(objnewRow);
dg2.DataSource = objTable.DefaultView;
dg2.DataBind();
OleDbCommandBuilder objBuilder = null;
objBuilder = new OleDbCommandBuilder(objAdapter);
//objAdapter.UpdateCommand = objBuilder.GetUpdateCommand();
//objAdapter.InsertCommand.CommandText = "INSERT INTO login(brugernavn, password, nummer) VALUES(sgfg,wrfgwrfg,wrfwrf)";
objAdapter.InsertCommand = objBuilder.GetInsertCommand();
//objAdapter.DeleteCommand = objBuilder.GetDeleteCommand();
L1.Text = objAdapter.InsertCommand.CommandText;
objAdapter.Update(objDataSet, "login");
strSQL = "SELECT * FROM login";
objConnection.Open();
OleDbCommand objCmd = new OleDbCommand(strSQL, objConnection);
dgUpd.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection);
dgUpd.DataBind();
}
public indtast_resultat() {
}
}
}
Men jer får følgende fejl:
[OleDbException (0x80040e14): Der er en syntaksfejl i INSERT INTO-sætningen.]
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +1662
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) +152
tune.indtast_resultat.Page_Load(Object sender, EventArgs e) +479
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731