Problemer med at indsætte data i MSSQL database
Hejsa,Er netop begyndt på ASP.NET efter tidligere at have programmeret i ASP, og jeg har en hel del problemer med at indsætte data i min MS SQL 2005 database.
Jeg har en form hvor brugere kan oprette en profil...
Jeg bruger en SqlDataSource:
<asp:SqlDataSource ID="datNewUser" ConnectionString="<%$ onnectionStrings:mytrendConnectionString %>" InsertCommand="INSERT siteusers (Username, Password, Email, BirthDate, Zipcode, Gender, Mobil, Region) VALUES (@UserName, @Password, @Email, @BirthDate, @Zipcode, @Gender, @Mobil, @Region)" runat="server">
</asp:SqlDataSource>
Min submit button kalder så følgende i min Code-behind fil:
protected void btnSubmit_Click(object sender, EventArgs e)
{
datNewUser.InsertParameters.Add("UserName", xtUserName.Text);
datNewUser.InsertParameters.Add("Password", txtPassword.Text);
datNewUser.InsertParameters.Add("Email", txtEmail.Text);
datNewUser.InsertParameters.Add("BirthDate", txtBirthday.Text);
datNewUser.InsertParameters.Add("Zipcode", txtZipcode.Text);
datNewUser.InsertParameters.Add("Gender", rdoGender1.Checked.ToString());
datNewUser.InsertParameters.Add("Mobil", txtMobil.Text);
datNewUser.InsertParameters.Add("Region", DropDownList1.SelectedValue);
datNewUser.Insert();
}
Jeg får så følgende fejl meddelelse:
Arithmetic overflow error converting expression to data type smalldatetime.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Arithmetic overflow error converting expression to data type smalldatetime.
The statement has been terminated.
Source Error:
Line 26: datNewUser.InsertParameters.Add("Mobil", txtMobil.Text);
Line 27: datNewUser.InsertParameters.Add("Region", DropDownList1.SelectedValue);
Line 28: datNewUser.Insert();
Line 29: }
Line 30: }
Source File: c:\Documents and Settings\Kasper Christensen\My Documents\Visual Studio 2005\WebSites\MyTrendAjax\NewUser.aspx.cs Line: 28
Det eneste smalldatetime field i min database er BirthDate...