Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Insert into SQL Table

Author  Topic 

igorblackbelt
Constraint Violating Yak Guru

407 Posts

Posted - 2006-05-05 : 16:39:57
I know, it should be easy... But I'm a newbie on asp.net ... I can't figure this out.
The msg says the error is in line 39 (See in bold below). I thought it was the insert t-sql.

Imports System.Data.SqlClient

Partial Class _Default
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'Protected WithEvents ButtonSubmitForm As System.Web.UI.WebControls.Button
'Protected WithEvents Date1 As System.Web.UI.WebControls.TextBox
'Protected WithEvents ServType As System.Web.UI.WebControls.TextBox
'Protected WithEvents SENum As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData()
End Sub

Private Sub ButtonSubmitForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubmitForm.Click
Dim strConn As String = "data source=SERVER; User ID=USER; Password=PASS; Persist Security Info=True;packet size=4096"
'Dim cmd As New SqlCommand("INSERT INTO Date, [Service Type], [SE Num]VALUES ('" & Date1.Text & "', '" & ServType.Text & "', '" & SENum.Text & "')", New SqlConnection(strConn))
Dim cmd As New SqlCommand("INSERT INTO Date, [Service Type], [SE Num] VALUES ('11/11/2006', 'Format123', '12345678910')", New SqlConnection(strConn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
LoadData()
End Sub

Sub LoadData()
Dim strConn As String = "data source=SERVER; User ID=USER; Password=PASS; Persist Security Info=True;packet size=4096"
Dim strSQL As String = "Select * From tblMerchantsTRACES"
Dim cmd As New SqlCommand(strSQL, New SqlConnection(strConn))
cmd.Connection.Open()
'Repeater1.DataSource = cmd.ExecuteReader
'Repeater1.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
End Sub

End Class


---

Thanks!
Igor.

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-05 : 17:20:32
You don't mention what the error was, but your insert command is bad. You need to indicate the table and the columns you are inserting into...

INSERT INTO SomeTable (Date, [Service Type], [SE Num]) VALUES ('11/11/2006', 'Format123', '12345678910')
Go to Top of Page
   

- Advertisement -