archaeofreak
New member
- Joined
- Mar 9, 2013
- Messages
- 2
- Programming Experience
- Beginner
Here is my code:
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing.Printing
Public Class frmAddProject
Private Sub frmAddProject_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim ProjectName As String
Dim NumAffected As Integer
ProjectName = txtProjectName.Text
Try
cn.ConnectionString = "Data Source=LENOVO-T60\SQLEXPRESS;Initial Catalog=ArchDatabase;Integrated Security=True"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "INSERT INTO ProjectTable([Project Name]) VALUES(@ProjectName,)"
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table.")
Finally
MsgBox(NumAffected.ToString + " New Project Added")
cn.Close()
End Try
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
End Class
I am just trying to simply add a new project to my project table. I have a textbox that the user types in the name of the project and a button to save the name to the table. The debugger runs fine, and the exception handler catches, displaying the error message and 0 new projects added. No data is written to the SQL table. The Do Not Copy setting is set already.
Help appreciated!
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing.Printing
Public Class frmAddProject
Private Sub frmAddProject_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim ProjectName As String
Dim NumAffected As Integer
ProjectName = txtProjectName.Text
Try
cn.ConnectionString = "Data Source=LENOVO-T60\SQLEXPRESS;Initial Catalog=ArchDatabase;Integrated Security=True"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "INSERT INTO ProjectTable([Project Name]) VALUES(@ProjectName,)"
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table.")
Finally
MsgBox(NumAffected.ToString + " New Project Added")
cn.Close()
End Try
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
End Class
I am just trying to simply add a new project to my project table. I have a textbox that the user types in the name of the project and a button to save the name to the table. The debugger runs fine, and the exception handler catches, displaying the error message and 0 new projects added. No data is written to the SQL table. The Do Not Copy setting is set already.
Help appreciated!