hi guys im new here and i want to show the appointments in currentdate in vb.net using mysql here is my code heres my code
cn.Open()
cm = New MySqlCommand("select count(*) from tblappointment where date=" & Date.Today & "", cn)
frmDashBoard.lblAppointment.Text = Format(CLng(cm.ExecuteScalar), "#,##0")
cn.Close()
You would do it diirectly in mysql
cn.Open()
cm = New MySqlCommand("select count(*) from table1 where `date`= cur_date", cn)
frmDashBoard.lblAppointment.Text = Format(CLng(cm.ExecuteScalar), "#,##0")
cn.Close()
But for the future when you add variables to your code use placeholders for
dim name as string
cnn.ConnectionString = "............"
cmd.Connection = cnn
cnn.Open()
cmd.CommandText = "SELECT Name, adress from tblappointment WHERE ID= #id"
cmd.Parameters.AddWithValue("#id", txtIDInput.Text )
Dim reader = cmd.ExecuteReader()
while reader.Read()
name= reader(1).ToString()
End While
Related
This is my code in login button.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim InsertRecordID As Integer
Using connection As New MySqlConnection(OPConStr1),
cmd As New MySqlCommand("SELECT `StudentId` FROM `usersaccount` WHERE `StudentID` = #username AND `AccountPassword` = #password", connection)
cmd.Parameters.Add("#username", MySqlDbType.VarChar).Value = Username.Text
cmd.Parameters.Add("#password", MySqlDbType.VarChar).Value = Pass.Text
connection.Open()
InsertRecordID = CInt(cmd.ExecuteScalar())
End Using
If InsertRecordID = 0 Then
MessageBox.Show("Invalid Username Or Password")
Else
Dim OPConStr1 As String = "server=localhost;username=root;password=;database=logs"
Dim strSql = "Insert into logs.logrecord (StudentID, Status, TimeUsed, remainingTime) Values (#ID, #Status, #TimeUsed, #remainingTime);"
Using connection As New MySqlConnection(OPConStr1)
Dim cmd1 As New MySqlCommand("SELECT remainingTime FROM usersaccount.usersaccount where StudentID = " + Username.Text, connection)
Dim dt As New DataTable()
Dim adapter As New MySqlDataAdapter(cmd1)
adapter.Fill(dt)
Dim remTime1 = Convert.ToString(dt.Rows(0).ItemArray(0).ToString())
Using con As New MySqlConnection("Data Source=localhost;Initial Catalog=logs;User ID= root; password=07292021;Pooling=False"),
cmd As New MySqlCommand(strSql, con)
cmd.Parameters.Add("#ID", MySqlDbType.VarChar).Value = InsertRecordID
cmd.Parameters.Add("#Status", MySqlDbType.VarChar).Value = "LoggedIN"
cmd.Parameters.Add("#TimeUsed", MySqlDbType.VarChar).Value = "-"
cmd.Parameters.Add("#remainingTime", MySqlDbType.VarChar).Value = remTime1
con.Open()
cmd.ExecuteScalar()
Me.Close()
RemaingTime.Show()
End Using
End Using
End If
End Sub
the next one is my code for logout button
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim remsec = remseconds - OccupiedSeconds
Dim strSql = "Insert into logs.logrecord (StudentID, Date, Status,RemainingTime, TimeUsed) Values (#ID, #Log, #Status, #remainingTime, TimeUsed);"
Using cn As New MySqlConnection(OPConStr),
cmd As New MySqlCommand(strSql, cn)
cmd.Parameters.Add("#ID", MySqlDbType.VarChar).Value = SomeModule.LogInRecordID
cmd.Parameters.Add("#Log", MySqlDbType.DateTime).Value = Now()
cmd.Parameters.Add("#Status", MySqlDbType.VarChar).Value = "LoggedOUT"
cmd.Parameters.Add("#TimeUsed", MySqlDbType.Int32).Value = ""
cmd.Parameters.Add("#remainingTime", MySqlDbType.Int32).Value = remsec
cn.Open()
cmd.ExecuteScalar()
End Using
Application.Exit()
End Sub
I really don't have enough knowledge about vb and I'm still learning so bear with me. My problem is I didn't know exactly what code will be used to get the difference between loggedin and loggedout date knowing that these two datas are in same column
here's my code
MysqlConn.Open()
command.Connection = MysqlConn
command.CommandText = CommandType.Text
command.CommandText = "INSERT INTO order VALUES (#1,#2,#3,#4,#5,#6,#7,#8)"
command.Parameters.AddWithValue("#1", rw.Cells(0).Value)
command.Parameters.AddWithValue("#2", rw.Cells(1).Value)
command.Parameters.AddWithValue("#3", rw.Cells(2).Value)
command.Parameters.AddWithValue("#4", rw.Cells(3).Value)
command.Parameters.AddWithValue("#5", Now())
command.Parameters.AddWithValue("#6", TextBox6.Text)
command.Parameters.AddWithValue("#7", TextBox7.Text)
command.Parameters.AddWithValue("#8", TextBox8.Text)
command.ExecuteNonQuery()
Next
MsgBox("done")
MysqlConn.Close()
command.Parameters.Clear()
i already did the "insert into order (names, .....) values (#1,....) but still not working. im using mysql
Dim I As Integer
For I = 0 To Dgrd.Rows.Count - 2
Dim row As DataGridViewRow = Dgrd.Rows(I)
Dim SQLCON As New SqlConnection(MyDataBaseCon)
Dim CMD As SqlCommand
Dim S1 As DataGridViewTextBoxCell = row.Cells(1)
Dim S2 As DataGridViewTextBoxCell = row.Cells(2)
Dim S3 As DataGridViewTextBoxCell = row.Cells(3)
CMD = New SqlCommand("Insert Into order
(S1,S2,S3) Values (#S1,#S2,#S3)", SQLCON)
SQLCON.Open()
CMD.Parameters.Add(New SqlParameter("#S1", SqlDbType.Int)).Value = S1
CMD.Parameters.Add(New SqlParameter("#S2", SqlDbType.Int)).Value = S2
CMD.Parameters.Add(New SqlParameter("#S3", SqlDbType.NVarChar, 50)).Value = S3
CMD.ExecuteNonQuery()
SQLCON.Close()
Next
MsgBox("done")
I was making a vb program that searches a student info by searching a course.. For example Ajax's course is "BSCS" and DP's course is "BSIT" , then i'm going to select BSCS, so Ajax's must only appear not DP. The result appear's in DataGridView
myConnection.Open()
Dim str As String
str = "SELECT * FROM students WHERE (Course = '" & TextBox1.Text & "')"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader
While dr.Read()
FirstNameTextBox = dr("FirstName")
MiddleNameTextBox = dr("MiddleName")
LastNameTextBox = dr("LastName")
AddressTextBox = dr("Address")
CellphoneNumberTextBox = dr("CellphoneNumber")
CourseTextBox = dr("Course")
End While
myConnection.Close()
Based on your Code you should add new DataGridView to your form and also adding columns with header name that you choose and replace the code with mine
myConnection.Open()
Dim str As String
str = "SELECT * FROM students WHERE (Course = '" & TextBox1.Text & "')"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader
While dr.Read()
DataGridView1.Rows.Add({dr("FirstName"), dr("MiddleName"), dr("LastName"), dr("Address"), dr("CellphoneNumber"), dr("Course")})
End While
myConnection.Close()
I am newbie in mysql and vb.net and have this query:
select `db_employee`.`firstName` as `firstName`, `db_employee`.`lastName` as `lastName`,
`tbl_employment`.`position` as `position`
from (`db_employee` `db_employee`
inner join `tbl_employment` `tbl_employment` on (`tbl_employment`.`ctrlID` = `db_employee`.`ctrlID`))
where (`tbl_employment`.`companyName` like 'MES%')
And I want to convert it to be used here:
Dim MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = connStr
Dim SDA As New MySqlDataAdapter
Dim dbdataset As New DataTable
Dim bsource As New BindingSource
MySqlConn.Open()
Dim query As String
query = ?
you can use below code for displaying data... i hope this what you want.. :)
Dim cn As SqlConn= New SqlConn("Connecting String")
Dim cmd As sqlCommand
Dim dr As sqlDataReader
cn.open()
cmd = New sqlCommand("select * from table or your query, cn)
dr = cmd.ExecuteReader()
dr.Read()
textbox1.Text = dr(1).ToString()
cn.close()
You can do something like this with the MySQL provider you're using. This will create your connection, command and data reader and close and dispose of everything properly. If you want a DataTable instance, you can load it from the DataReader.
Using conn As New MySql.Data.MySqlClient.MySqlConnection("YourConnectionString")
conn.Open()
Using cmd As MySql.Data.MySqlClient.MySqlCommand = conn.CreateCommand
cmd.CommandText = "select db_employee.firstName as firstName, " & _
"db_employee.lastName as lastName, " & _
"tbl_employment.position as position " & _
"from db_employee db_employee " & _
"inner join tbl_employment tbl_employment on tbl_employment.ctrlID = db_employee.ctrlID " & _
"where tbl_employment.companyName like 'MES%' "
' Get a data reader that you can loop over or load a data table with
Dim dr As MySql.Data.MySqlClient.MySqlDataReader = cmd.ExecuteReader
' How to read with a DataReader
While dr.Read
' Do something with this
Dim lastName As String = dr("lastName")
End While
End Using
conn.Close()
End Using
Try
cn.Open()
Dim query As String
Dim fname As String
Dim reader As MySqlDataReader
query = "Select emp_id,emp_fname,emp_lname,empmname,position,branch from dtrsystem.tblemployee where emp_id = '" & Class1.empid & "' "
sql = New MySqlCommand(query, cn)
reader = sql.ExecuteReader
cn.Close()
Catch ex As Exception
End Try
i want to store my emp_id,emp_fname,emp_lname,empmname,position,branch in a variable and show it in a label. I'm new to vb.net and tried the codes i've searched but it doesnt work. please help
''declare variables v1,v2,v3
Try
cn.Open()
Dim query As String
Dim fname As String
Dim reader As MySqlDataReader
query = "Select emp_id,emp_fname,emp_lname,empmname,position,branch from dtrsystem.tblemployee where emp_id = '" & Class1.empid & "' "
sql = New MySqlCommand(query, cn)
reader = sql.ExecuteReader
while reader.read
v1=reader(0) 'emp id
v2=reader(1) 'emp fname
v3=reader(2) ' emp lname
''etc
End While
cn.Close()
Catch ex As Exception
End Try