Results 1 to 7 of 7

Thread: [2005] Giving value to a Paramiter

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    76

    [2005] Giving value to a Paramiter

    hi i want to save either number 1 or 0 for my Owner field in my databass but the code that i have dose not do the job can someone help please?

    Code:
    If Me.btnOwner2.UseVisualStyleBackColor = False Then
                    command.Parameters.AddWithValue("Owner", 1)
                Else
                    command.Parameters.AddWithValue("Owner", 0)
                End If
    thank you

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Giving value to a Paramiter

    That code doesn't save anything. It just sets a parameter value. Where's the rest of the code?

    Also, what type of database is this? If it's SQL Server then bit columns are actually Booleans, not Integers, in VB code. In that case you should just be assigning the value of UseVisualStyleBackColor directly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    76

    Re: [2005] Giving value to a Paramiter

    sorry i am using ms 2003.

    Code:
           If txtUserName.Text = "" Then
                MessageBox.Show("Please enter a User Name.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
    
            If txtPassword.Text = "" Then
                MessageBox.Show("Please enter a Password.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
    
      
    
                Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\CashUp\Datas.mdb")
                Dim command As New OleDb.OleDbCommand("INSERT INTO tblUsers ([User], [Password]) VALUES ([@User], [Password])", connection)
                Dim comm As New OleDb.OleDbCommand("SELECT COUNT (User) FROM tblUsers WHERE User = '" & txtUserName.Text & "'", connection)
    
                connection.Open()
                Dim total As Double = CDbl(comm.ExecuteScalar())
    
                If total = "1" Then
                    MessageBox.Show("User Already Exists ", "Existing Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    txtUserName.Text = ""
                    txtPassword.Text = ""
                    txtUserName.Focus()
    
                Else
                    command.Parameters.AddWithValue("[@User]", Me.txtUserName.Text)
                    command.Parameters.AddWithValue("[@Password]", Me.txtPassword.Text)
    
    
                    If Me.btnOwner2.UseVisualStyleBackColor = False Then
                    command.Parameters.AddWithValue("Owner", 1)
                    Else
                        command.Parameters.AddWithValue("Owner", 0)
                    End If
    
    
                    If Me.btnManager2.UseVisualStyleBackColor = False Then
                        command.Parameters.AddWithValue("Manager", 1)
                    Else
                        command.Parameters.AddWithValue("Manager", 0)
                    End If
    
    
                    If Me.btnDriver2.UseVisualStyleBackColor = False Then
                        command.Parameters.AddWithValue("Driver", 1)
                    Else
                        command.Parameters.AddWithValue("Driver", 0)
                    End If
    
                    command.ExecuteNonQuery()
                    connection.Close()
                    MessageBox.Show("New user added successfuly.", " ", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    txtUserName.Text = ""
                    txtPassword.Text = ""
                    Me.UsersGroup2.Enabled = False
                Me.UsersGruop.Enabled = True
                List1.Items.Clear()
    
                Dim command1 As New OleDb.OleDbCommand("SELECT (User) FROM tblUsers", connection)
                connection.Open()
                Dim UserRead As OleDb.OleDbDataReader
                UserRead = command1.ExecuteReader()
                Do While UserRead.Read
                    Me.List1.Items.Add(UserRead.Item("User"))
                Loop
                connection.Close()
    Last edited by afshin_tt; Nov 11th, 2008 at 03:06 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Giving value to a Paramiter

    Are you really using VB.NET 2003? You've specified 2005 when you posted. If you're using 2003 then AddWithValue would have refused to compile, which you haven't mentioned. If you're not clear about what's happening then we can't help.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    76

    Re: [2005] Giving value to a Paramiter

    hi
    you asked what database i am using in your priviuse post, i am using MS Access 2003, and vb.net 2005

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Giving value to a Paramiter

    try this:

    vb Code:
    1. If Me.btnOwner2.UseVisualStyleBackColor = False Then
    2.    command.Parameters.AddWithValue("Owner", true)
    3. Else
    4.    command.Parameters.AddWithValue("Owner", false)
    5. End If

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Giving value to a Paramiter

    Quote Originally Posted by afshin_tt
    hi
    you asked what database i am using in your priviuse post, i am using MS Access 2003, and vb.net 2005
    Aha. "MS" is Microsoft, so MS 2003 doesn't really mean anything. Access was what I was interested in. Like I said, There's not much point testing a Boolean value to decide what Boolean value to assign. Just assign the original Boolean value in the first place:
    vb.net Code:
    1. command.Parameters.AddWithValue("Owner", Not Me.btnOwner2.UseVisualStyleBackColor)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width