Please take a look at the code below. It is a copy of the coding of a function and a subroutine I've coded in my program.
The SQL Database VBDB has the table Users defined so that the default access level is 0.
The problem is that the access level is 0 no mater what access level is put in the program. I've run the same command in SQL, there it runs fine.
Please do tell me what the problem is.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Acc_Lvl As Integer Dim user, passwd, var As String passwd = "" user = NameBox.Text If (String.Compare(PassBox.Text, PassBox2.Text)) = 0 Then passwd = PassBox.Text Else MsgBox("Password and Re Enter password fields don't match") End If 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 AddUserFun(user, passwd, Acc_Lvl) MsgBox("The User has been created") End Sub
Function AddUserFun(ByRef user, ByRef pass, ByRef acclvl) As Integer Dim i As Integer Try Dim conn As New SqlClient.SqlConnection("server=PG-COMP1;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 am going out of my mind,the code worked fine till I uninstalled and reinstalled SQL Server 2008 R2, now it doesn't work!!
It is the code I developed for my final project at college, please do help me out!!