所以我仍然是ASP.Net的新手。我创建了一个最终用户填写的Web表单。然后他们单击一个提交按钮,数据被支持插入到SQL DB中。
当您单击“提交”按钮时,弹出警告窗口将显示“已添加新记录”,但是当我在管理工作室中查询数据库时,新记录不存在。为了让事情变得更奇怪,我在任何地方都没有任何错误。我究竟做错了什么?任何帮助是极大的赞赏!
这是我的代码:
Dim par_db_connstring As String = ConfigurationManager.ConnectionStrings("PAR_DB_Conn").ConnectionString
Using sqlConn = New SqlConnection(par_db_connstring)
Using sqlCmd As New SqlCommand(SqlStatment, sqlConn)
'Adding paramaters
sqlCmd.Parameters.AddWithValue("@parNum", par_Number)
sqlCmd.Parameters.AddWithValue("@parDate", parDate_Ins)
sqlCmd.Parameters.AddWithValue("@submittedby", submittedby_Ins)
sqlCmd.Parameters.AddWithValue("@area", ddlArea_Ins)
sqlCmd.Parameters.AddWithValue("@currentstatus", ddlStatus_Ins)
sqlCmd.Parameters.AddWithValue("@job_num", jobNum_Ins)
sqlCmd.Parameters.AddWithValue("@customer", customer_Ins)
sqlCmd.Parameters.AddWithValue("@mfg_cost", mfgcost_Ins)
sqlCmd.Parameters.AddWithValue("@inv_cost", invcost_Ins)
sqlCmd.Parameters.AddWithValue("@problem_type", problemType_Ins)
sqlCmd.Parameters.AddWithValue("@problem_description", problem_description_Ins)
sqlCmd.Parameters.AddWithValue("@action_required", actionRequired_Ins)
sqlCmd.Parameters.AddWithValue("@corrective_action", correctiveAction_Ins)
Try
If sqlConn.State <> ConnectionState.Open Then
sqlConn.Open()
End If
Dim recAff As Integer = sqlCmd.ExecuteNonQuery
Response.Write("<script>alert('" + recAff.ToString() + "')</script>")
Catch generatedExceptionName As SqlException
Response.Write("<script>alert('" + generatedExceptionName.ToString() + "')</script>")
End Try
End Using
End Using
Dim insMsg As String = "New PAR Record Added..."
Response.Write("<script>alert('" + insMsg + "')</script>")
Response.Write("<script language='javascript'> { window.close();}</script>")
这是连接字符串:
<add name="PAR_DB_Conn" connectionString="Data Source=O-SN-2I-LT-101\SQLEXP14;Initial Catalog=PAR;User ID=<User ID>;Password=<Password>" providerName="System.Data.SqlClient" />