So I have another problem doing my school project. FYI, we don't use sql-parameters and didn't learn how to use them as of yet.
I am trying to insert a birthday into the sql database but I tried everything but there is always a data type mismatch.
Can you guys help me out (without changing the structure of the code)? You can look it up by searching "birthday" as everything else has German names.
I would really appreciate your help as I'm really desperate. EDIT: There is a textbox, where user are supposed to type in the birthday. That's where I get the data.
EDIT: I removed all other unnecessary strings etc.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
public class webUser
{
private DateTime _birthday;
public webUser()
{
//
// TODO: Add constructor logic here
//
public DateTime birthday
{
get { return _birhday; }
set { _birthday= value; }
}
public bool checkUser(string eMail)
{
string sql = "SELECT eMail, kennwort FROM Benutzerdatenbank WHERE eMail ='" + eMail + "'";
string conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Benutzerdatenbank.accdb");
OleDbConnection con = new OleDbConnection(conStr);
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count == 1)
return true;
else
return false;
}
public bool addUser(string eMail, string kennwort, string vorname, string zuname, string telefonnummer, string strasse, string plz, string ort, string firma, string titel, DateTime birthday)
{
if (this.checkUser(eMail) == true)
{
return false;
}
else
{
string zeichen = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjiklmnopqrstuvwxyz0123456789";
string aktivierungscode = "";
Random rnd = new Random();
for (int i = 1; i < 62; i++)
{
aktivierungscode = aktivierungscode + zeichen.Substring(rnd.Next(0, zeichen.Length - 1), 1);
}
string sql = "INSERT INTO Benutzerdatenbank (eMail, kennwort, Titel, Vorname, Zuname, Firma, birthday, Telefonnummer, Strasse, PLZ, Ort, aktivierungscode) VALUES ('" +
eMail + "','" + kennwort + "','" + titel + "','" + vorname + "','" + zuname + "','" + firma + "','" + birthday+ "','" + telefonnummer + "','" + strasse + "','" + plz + "','" + ort + "','" + aktivierungscode + "');";
string conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Benutzerdatenbank.accdb");
OleDbConnection con = new OleDbConnection(conStr);
OleDbCommand cmd = new OleDbCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
return true;
}
}
public void ReadUser(string eMail, string kennwort)
{
string sql = "SELECT * FROM Benutzerdatenbank WHERE eMail='" + eMail + "' AND kennwort ='" + kennwort + "'";
string conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Benutzerdatenbank.accdb");
OleDbConnection con = new OleDbConnection(conStr);
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count == 1)
{
this.eMail = (string)ds.Tables[0].Rows[0]["eMail"];
this.vorname = (string)ds.Tables[0].Rows[0]["Vorname"];
this.zuname = (string)ds.Tables[0].Rows[0]["Zuname"];
this.telefonnummer = (string)ds.Tables[0].Rows[0]["Telefonnummer"];
this.strasse = (string)ds.Tables[0].Rows[0]["strasse"];
this.plz = (string)ds.Tables[0].Rows[0]["PLZ"];
this.ort = (string)ds.Tables[0].Rows[0]["ORT"];
this.titel = (string)ds.Tables[0].Rows[0]["Titel"];
this.firma = (string)ds.Tables[0].Rows[0]["Firma"];
this.birthday= Convert.ToDateTime(ds.Tables[0].Rows[0]["birthday"];
}
else
{
this.eMail = "";
this.vorname = "";
this.zuname = "";
}
}
}