derzeit habe ich ein sehr seltsames Problem während meiner C# & asp.net Web OOP lernen konfrontiert. Ich habe den Code für das Einfügen von Daten in Microsoft Access geschrieben, egal wie ich versuche, die Daten werden nie in meine DB einfügen, obwohl der Code korrekt ist.Fehler beim Einfügen von Daten ohne Fehler
Irgendwie in anderen Projekt verwende ich die gleiche Methode zu tun ist funktioniert ... Wünschte jemand kann hier helfen. Danke.
using System.Data.OleDb;
public class DataBaseCon
{
private static OleDbConnection GetConn()
{
string ConString;
ConString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\YogaDB.accdb";
return new OleDbConnection(ConString);
}
public static void Register(string un, string pw, DateTime dob, int ye, string hissue, string email, string contact)
{
OleDbConnection myConnection = GetConn();
string myQuery = "INSERT INTO User(Username, Password, DateOfBirth, YogaExp, HealthIssue, Email, Contact, UserType) VALUES ('" + un + "' , '" + pw + "' , '" + dob + "' , '" + ye + "', '" + hissue + "' , '" + email + "', '" + contact + "', 'student')";
OleDbCommand myCommand = new OleDbCommand(myQuery, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Exception in DBHandler", ex);
}
finally
{
myConnection.Close();
}
}
}
Taste Funktion hier:
protected void RegisterBtn_Click(object sender, EventArgs e)
{
string un = TextBox1.Text;
string pw = TextBox2.Text;
DateTime dob = Calendar1.SelectedDate;
int ye = int.Parse(TextBox4.Text);
string hissue = TextBox5.Text;
string email = TextBox6.Text;
string contact = TextBox7.Text;
DataBaseCon.Register(un, pw, dob, ye, hissue, email, contact);
Label8.Text = "Congratulation "+ un +" , success to register!";
}
Erhalten Sie eine Ausnahme? – Pikoh
** Warnung ** Yoru-Code ist extrem anfällig für SQL-Injektion. –
keine ausnahme, fehler? und hast du die Registrierungsmethode debuggt? – Badiparmagi