当我尝试插入数据库时,会显示以下消息:
无法访问此网站
连接已重置。 尝试: 检查连接。
检查代理服务器和防火墙。
运行Windows网络诊断数据
我的代码是:
Protected Sub btnYes_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnYes.Click
Dim bday As String = DropDownList11.SelectedItem.ToString & "/" & DropDownList10.SelectedItem.ToString & "/" & DropDownList12.SelectedItem.ToString
Try
Dim conn1 As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\pc1\Desktop\WebApplication1111\WebApplication1\App_Data\StudentRegistration.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim cmd As New SqlCommand("insert into students values(@std_nn, @std_sn, @std_fn, @stdsecn, @std_midn, @std_ln, @std_gndr, @std_bday, @std_cbirth, @std_ident, @stdmstatus, @std_mail, @std_phone, @std_ppic, @std_rstatus, @std_spec, @std_twjavg, @std_twjtype)", conn1)
Dim affectedrow As Integer
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@std_nn", Session("studentno").ToString)
cmd.Parameters.AddWithValue("@std_fn", TextBox2.Text)
cmd.Parameters.AddWithValue("@stdsecn", TextBox3.Text)
cmd.Parameters.AddWithValue("@std_midn", TextBox4.Text)
cmd.Parameters.AddWithValue("@std_ln", TextBox5.Text)
cmd.Parameters.AddWithValue("@std_gndr", DropDownList1.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@std_bday", bday)
cmd.Parameters.AddWithValue("@std_cbirth", TextBox6.Text)
cmd.Parameters.AddWithValue("@std_ident", TextBox7.Text)
cmd.Parameters.AddWithValue("@stdmstatus", DropDownList2.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@std_mail", TextBox8.Text)
cmd.Parameters.AddWithValue("@std_phone", TextBox9.Text)
cmd.Parameters.AddWithValue("@std_ppic", Image1.ImageUrl.ToString)
cmd.Parameters.AddWithValue("@std_rstatus", "waiting")
cmd.Parameters.AddWithValue("@std_spec", DBNull.Value)
cmd.Parameters.AddWithValue("@std_twjavg", TextBox10.Text)
cmd.Parameters.AddWithValue("@std_twjtype", DropDownList3.SelectedItem.ToString)
If conn1.State = ConnectionState.Closed Then
conn1.Open()
affectedrow = cmd.ExecuteNonQuery()
End If
conn1.Close()
If affectedrow > 0 Then
add_subjects()
add_attachments()
Label1.Text = "done"
Response.Redirect("Stdinfo.aspx")
End If
Catch ex As Exception
Label1.Text = "error"
End Try
End Sub