|
-
Nov 10th, 2008, 05:15 PM
#1
Thread Starter
Lively Member
[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
-
Nov 10th, 2008, 07:01 PM
#2
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.
-
Nov 11th, 2008, 02:58 PM
#3
Thread Starter
Lively Member
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.
-
Nov 11th, 2008, 06:51 PM
#4
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.
-
Nov 12th, 2008, 04:51 PM
#5
Thread Starter
Lively Member
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
-
Nov 12th, 2008, 05:09 PM
#6
Re: [2005] Giving value to a Paramiter
try this:
vb Code:
If Me.btnOwner2.UseVisualStyleBackColor = False Then
command.Parameters.AddWithValue("Owner", true)
Else
command.Parameters.AddWithValue("Owner", false)
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 12th, 2008, 06:08 PM
#7
Re: [2005] Giving value to a Paramiter
 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:
command.Parameters.AddWithValue("Owner", Not Me.btnOwner2.UseVisualStyleBackColor)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|