关于将数据从文本框(ASP)插入到sql数据库 [英] About Insert data from textbox (ASP) to sql database
问题描述
大家好,我在将数据从文本框插入sql数据库的代码中遇到了问题,它没有给我一个错误消息,但是它不起作用,并且给了我我在代码&中编写的错误消息我不知道问题出在哪里?
请问有人告诉我哪里错了吗?
感谢advanc
hello everybody I have a problem in my code of inserting data from textbox to sql database , it doesn''t give me an a error message but it''s not work and give me the error message which I write in the code & I don''t know where is the problem?
plz anyone told me where is the mistake?
thanks in advanc
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ControlConnectionString").ConnectionString
Dim Conn As New sqlConnection(ConnString)
Dim Comm As SqlCommand
Dim reader As SqlDataReader
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Comm = New SqlCommand("Insert into StudentData(SettingID)" & "values(@SettingID,0)", Conn)
Comm.Parameters.Add("@SettingID", Data.SqlDbType.NVarChar, 50)
Comm.Parameters("@SettingID").Value = TextBox1.Text
Try
Conn.Open()
Comm.ExecuteNonQuery()
Response.Redirect("Default2.aspx")
Catch
Label1.Text = "ERROR, Try Again"
Finally
Conn.Close()
End Try
End Sub
End Class
推荐答案
查看您的SQL INSERT语句:
Look at your SQL INSERT statement:
Insert into StudentData(SettingID)values(@SettingID,0)
看到任何问题吗?
不应该是:
See any problem with that?
Shouldn''t that be:
Insert into StudentData(SettingID) values (@SettingID)
同样,您的Try/Catch块很糟糕,因为它吞下了实际的错误消息,并且只给您非常模糊的消息"ERROR,再试一次".这可能就是为什么您不知道出了什么问题的原因.
Also, your Try/Catch block sucks as it''s swallowing the actual error message and just giving you the very vague message "ERROR, Try again". This is probably why you have no idea what''s wrong.
这篇关于关于将数据从文本框(ASP)插入到sql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!