Dim strCon As String = WebConfigurationManager.ConnectionStrings("ProjectGIS").ConnectionString
Dim Conn As New SqlConnection()
Dim com As New SqlCommand
Dim FileName As String = FileUpload1.FileName
Dim location As String = Server.MapPath(".\Images\Pic_adm\") & FileName
Dim Job As Integer = DropDownList1.SelectedIndex + 1
Dim Sex As String = RadioButtonList1.Items.ToString
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strCon
.Open()
End With
If txtUsername.Text.Trim <> "" And txtPassword.Text.Trim <> "" And txtName.Text.Trim <> "" And txtSurname.Text.Trim <> "" _
And txtEmail.Text.Trim <> "" And txtTel.Text.Trim <> "" And txtQuestion.Text.Trim <> "" And txtAnswer.Text.Trim <> "" _
And FileUpload1.HasFile Then
If txtPassword.Text.Trim <> txtPasswordConfirm.Text.Trim Then
Label1.Text = "กรุณากรอก Password ให้ตรงกัน"
Else
FileUpload1.SaveAs(location)
Dim sqlStr2 As String
sqlStr2 = "INSERT INTO Login (Username,Password,Fname_adm,Lname_adm,Sex_adm,Job_id,Email_adm,Tell_adm,Question_adm,Answer_adm,Pic_adm) "
sqlStr2 &= "Values (@Username,@Password,@Fname_adm,@Lname_adm,@Sex_adm,@Job_id,@Email_adm,@Tell_adm,@Question_adm,@Answer_adm,@Pic_adm)"
With com
.CommandType = CommandType.Text
.CommandText = sqlStr2
.Connection = Conn
.Parameters.Clear()
.Parameters.Add("@Username", SqlDbType.VarChar).Value = txtUsername.Text.Trim
.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPassword.Text.Trim
.Parameters.Add("@Fname_adm", SqlDbType.VarChar).Value = txtName.Text.Trim
.Parameters.Add("@Lname_adm", SqlDbType.VarChar).Value = txtSurname.Text.Trim
.Parameters.Add("@Sex_adm", SqlDbType.VarChar).Value = Sex
.Parameters.Add("@Job_id", SqlDbType.Int).Value = Job
.Parameters.Add("@Email_adm", SqlDbType.VarChar).Value = txtEmail.Text.Trim
.Parameters.Add("@Tell_adm", SqlDbType.VarChar).Value = txtTel.Text.Trim
.Parameters.Add("@Question_adm", SqlDbType.VarChar).Value = txtQuestion.Text.Trim
.Parameters.Add("@Answer_adm", SqlDbType.VarChar).Value = txtAnswer.Text.Trim
.Parameters.Add("@Pic_adm", SqlDbType.VarChar).Value = FileName
.ExecuteNonQuery()
End With
End If
Else
Label1.Text = "กรุณากรอกข้อมูลให้ครบ"
End If
แจ้ง Error ดังนี้ครับ
String or binary data would be truncated.
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: String or binary data would be truncated.
The statement has been terminated.
Source Error:
Line 78: .Parameters.Add("@Answer_adm", SqlDbType.VarChar).Value = txtAnswer.Text.Trim
Line 79: .Parameters.Add("@Pic_adm", SqlDbType.VarChar).Value = FileName
Line 80: .ExecuteNonQuery()
Line 81: End With
Line 82: End If
Source File: C:\Documents and Settings\HPDV300\Desktop\PROJECT\GIS\AddProfile.aspx.vb Line: 80