Hi all,
I had originally installed MS SQL Server 2008 R2 in my C: when I was developing the application. While I had the SQL DErver in my C:, everything was fine, no problems at all. Then I began getting low disc space messages, so I uninstalled it from my C: and Installed it in a new external hard drive. But then I started having problems adding values in on field of a table.
SPECIFICS:
The application in concern is an application that has a table named Users that is the cause of my trouble. It has 3 fields, of which the application can update 2 faultlessly. It's a field called Access_Level that is having trouble getting valuse added to it. Whatever choice I enter in the form, the field only gets "0" as the value, which is not even in the list of choices! I would welcome help on determining why this happens, and how to get the table to take the value I want it to!!
CODE SNIPPETS:
FORM:
Public Class AddUser
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Acc_Lvl, done As Integer
Dim user, passwd, var As String
passwd = ""
user = NameBox.Text
If (String.Compare(PassBox.Text, PassBox2.Text)) = 0 Then
passwd = PassBox.Text
var = ListBox1.SelectedItem
Select Case var
Case "Level 1 ( ACCESS EVERYTHING)"
Acc_Lvl = 1
Case "Level 2 (CAN NOT ADD AND DELETE USER)"
Acc_Lvl = 2
Case "Level3 (CAN ONLY USE THE ORDERS PAGE AND VIEW THE BILLS)"
Acc_Lvl = 3
End Select
done = AddUserFun(user, passwd, Acc_Lvl)
If (done = 1) Then
MsgBox("User creation encountered an error")
Else
MsgBox("User Created")
End If
Else
MsgBox("Password and Re Enter password fields don't match")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
Opening_Form.Show()
End Sub
End Class
AddUserFun Function:
Function AddUserFun(ByVal user, ByVal pass, ByVal acclvl) As Integer
Dim i As Integer
Try
Dim conn As New SqlClient.SqlConnection("server=THE-507FC9ABDEB;uid=indrajeet6;pwd=Indrani7&;database=VBDB")
Dim addusr As New SqlClient.SqlCommand
addusr.CommandText = "INSERT INTO dbo.Users VALUES('" & user & "','" & pass & "','" & acclvl & "')"
addusr.CommandType = CommandType.Text
addusr.Connection = conn
conn.Open()
addusr.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
i = 1
End Try
i = 0
Return i
End Function
I have the SQL Generated Script fo the database generation also, if needed. The basic thing is that the table is defined As Follows:
CREATE TABLE [dbo].[Users](
[Username] [varchar](50) NOT NULL,
[Password] [varchar](50) NOT NULL,
[Access_Level] [int] NOT NULL
) ON [PRIMARY]
GO