I had executed a stored Procedure
Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
Dim con As New OdbcConnection(conStr)
Dim cmd As New OdbcCommand("dat.selectRowCount", con)
con.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("#startIndex", 5)
cmd.Parameters.AddWithValue("#endIndex", 15)
Dim reader As OdbcDataReader
reader = cmd.ExecuteReader
While reader.Read
'Some operations performed
End While
if i need to add this reader to a DataTable means
Dim dt As DataTable = New DataTable("adm_ttemp")
dt.Load(reader)
But how can i assign this reader to a DataSet ?
Why you are looking for a odbcReader to a dataSet assignment? you can directly read query result to a dataset as mentioned in the above answer?
Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
Dim con As New OdbcConnection(conStr)
Dim cmd As New OdbcCommand("dat.selectRowCount", con)
con.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("#startIndex", 5)
cmd.Parameters.AddWithValue("#endIndex", 15)
Dim DS As New DataSet
'<---- lines to be noticed
Using AD As New OdbcDataAdapter(cmd)
AD.Fill(DS)
End Using
You can call a stored procedure in following way, just try
Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
Dim con As New OdbcConnection(conStr)
Dim cmd As New OdbcCommand("dat.selectRowCount", con)
con.Open()
'<----
Dim callString As String = "CALL dat.selectRowCount(5,15)"
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = callString
'<-----
Dim dlist As New DataList
Dim DS As New DataSet
Using AD As New OdbcDataAdapter(cmd)
AD.Fill(DS)
End Using
I'd say to change your approach a little, and use an OdbcDataAdapter as follows:
Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
Dim con As New OdbcConnection(conStr)
Dim cmd As New OdbcCommand("dat.selectRowCount", con)
con.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("#startIndex", 5)
cmd.Parameters.AddWithValue("#endIndex", 15)
Dim DS as new DataSet
Using AD as new OdbcDataAdapter(cmd)
AD.Fill(DS)
End Using
' Perform your operations on the DataSet
Related
this is in my controller
string connStr = "server=" + IpAddress + ";user=" + UserName + ";database=" + DatabaseName + ";port=" + PortNumber + ";password=" + Password + ";SslMode=none;";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
string query = " select * from Cities,Regions";
MySqlCommand com = new MySqlCommand(query, conn);
MySqlDataAdapter da = new MySqlDataAdapter(com);
DataTable ds = new DataTable();
da.Fill(ds);
conn.Close();
I use a view model for displaying data from mysql and i fill them as below.
List<Models.ViewModels.city> CT = new List<Models.ViewModels.city>();
SftpClient sftpclient = new SftpClient("port", "root", "name");
sftpclient.Connect();
foreach (DataRow item in ds.Rows)
{
city ct = new city
{
CityName = item.itemArray[1].ToString(),
CityNumber = Convert.ToInt32(item.itemArray[2])
}
region rg = new region
{
RegionName = item.itemArray[1].ToString(),
RegionNumber = Convert.ToInt32(item.itemArray[2])
}
}
CT.Add(ct);
return View(CT.ToList());
How could i show regions in my razor. i already used viewbag for sending a list form my region viewmodel. but it doesn't fill the viewmodel obviously but how should i fill the region viewmodel
I'm trying to connect to MySQL from the other PC as I run my program it says that Unable to connect to any of the specified MySQL hosts
Dim strConn As String = "Server=192.168.xx.xx;Database=mydatabase;Uid=root;Pwd=mypassword;Port=3306"
Dim con As New MySqlConnection(strConn)
Dim cmd As New MySqlCommand("select * from station_tbl", con)
Dim adapter As New MySqlDataAdapter(cmd)
Dim dt As New DataTable()
Dim td As New DataTable()
adapter.Fill(dt)
adapter.Fill(td)
ComboBoxStationOrigin.DataSource = dt
ComboBoxStationDest.DataSource = td
ComboBoxStationOrigin.DisplayMember = "station_name"
ComboBoxStationDest.DisplayMember = "station_name"
ComboBoxStationOrigin.ValueMember = "station_id"
ComboBoxStationDest.ValueMember = "station_id"
The operation has timed out
objdbconn.OpenConn()
msSQL = " select google_name,google_password from hrm_mst_temployee " & _
" where employee_gid='" & Session("employee_gid") & "'"
objOdbcDataReader = objdbconn.GetDataReader(msSQL)
If objOdbcDataReader.HasRows = True Then
objOdbcDataReader.Read()
Try
user_password = objcmnfunctions.HttpDecodeFilePath(objOdbcDataReader.Item("google_password").ToString)
Catch
radnote.Text = "Problem Occurred While Decoding Password"
radnote.Show()
connect = 0
End Try
user_name = objOdbcDataReader.Item("google_name").ToString
End If
objOdbcDataReader.Close()
objdbconn.CloseConn()
Try
Dim contactser As New ContactsService("test")
contactser.setUserCredentials(user_name, user_password)
Dim newEntry As New ContactEntry()
newEntry.Title.Text = "(L)" & cbocompanyname.Text & "-" & txtcontactpersonname.Text
Dim primaryEmail As New EMail(txtEmail_ID.Text)
primaryEmail.Primary = True
primaryEmail.Rel = ContactsRelationships.IsWork
newEntry.Emails.Add(primaryEmail)
Dim phoneNumber As New PhoneNumber(txtcountrycode.Text & "-" & txtcontacttelephonenumber.Text)
phoneNumber.Primary = True
phoneNumber.Rel = ContactsRelationships.IsMobile
newEntry.Phonenumbers.Add(phoneNumber)
Dim name As New Name
name.FullName = "(L)" & cbocompanyname.Text & "-" & txtcontactpersonname.Text
newEntry.Name = name
Dim ims As New IMAddress
ims.Primary = True
Dim feedUri As New Uri(ContactsQuery.CreateContactsUri("default"))
Dim createdEntry As ContactEntry = DirectCast(contactser.Insert(feedUri, newEntry), ContactEntry)
Dim value As String = createdEntry.ExternalIds.ToString
Catch
radnote.Text = "Problem in Accessing Google Account"
radnote.Show()
End Try
End Sub
Ok so im trying to display everything in my MYSQL database using a datagrid view. but what i got is not working, can somebody help me with my code
Public Sub dataview()
DataGridView1.DataSource = ""
Dim bindingSource1 As New BindingSource()
Try
Dim cmd As New MySqlCommand("SELECT * FROM upload", db_con)
With Me.DataGridView1
.AutoGenerateColumns = True
bindingSource1.DataSource = cmd
.DataSource = bindingSource1
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.BorderStyle = BorderStyle.Fixed3D
.EditMode = DataGridViewEditMode.EditOnEnter
End With
DataGridView1.DataSource = bindingSource1
Catch ex As Exception
MessageBox.Show("something went wrong")
End Try
You cannot simply pass your MySqlCommand to the BindingSource.
You should use a object of type MySqlDataAdapter to get the command and fill a DataSet/DataTable.
That DataTable/DataSet should be used as DataSource for your bindingSource1
Dim cmd As New MySqlCommand("SELECT * FROM upload", db_con)
Dim da = New MySqlDataAdapter (cmd)
Dim dt = New DataTable()
da.Fill(dt)
bindingSource1.DataSource = dt ' here assign the DataTable'
With Me.DataGridView1
.AutoGenerateColumns = True
.DataSource = bindingSource1
.....
End With
Public Sub dataview()
DataGridView1.DataSource = ""
Dim bindingSource1 As New BindingSource()
Try
Dim cmd As New MySqlCommand("SELECT * FROM upload", db_con)
With Me.DataGridView1
.AutoGenerateColumns = True
bindingSource1.DataSource = cmd
.DataSource = bindingSource1
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.BorderStyle = BorderStyle.Fixed3D
.EditMode = DataGridViewEditMode.EditOnEnter
End With
DataGridView1.DataSource = bindingSource1
Catch ex As Exception
MessageBox.Show("something went wrong")
End Try
try this one^^
I have a code in restoring mysql database using vb.net. It perfectly works in windows 7 but when I try it in windows xp it's not working. Hope you can all help me with this. here's my code..
Function RestoreDb()
With dlg_openfile 'Executes a series of statements making repeated reference to a single object or structure.
.Title = "Please Select a Image" 'title
.InitialDirectory = "C:\" 'browse start directory
.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" 'only possible to select this extensions
.FilterIndex = 0 'index number filter
.FileName = "" 'empty
Dim answ = .ShowDialog
If answ = DialogResult.OK Then 'if answer not cancel, etc..
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.WorkingDirectory = "C:\wamp\bin\mysql\mysql5.5.24\bin\"
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
myStreamWriter.WriteLine(String.Format("mysql -u IS_DB -p2240624 db_innovaserver < {0}", .FileName))
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
End If
End With
End Function
Try this
Function RestoreDb()
With dlg_openfile 'Executes a series of statements making repeated reference to a single object or structure.
.Title = "Please Select a Image" 'title
.InitialDirectory = "C:\" 'browse start directory
.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" 'only possible to select this extensions
.FilterIndex = 0 'index number filter
.FileName = "" 'empty
Dim answ = .ShowDialog
If answ = DialogResult.OK Then 'if answer not cancel, etc..
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
myStreamWriter.WriteLine(String.Format("C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe -u IS_DB -p2240624 db_innovaserver < {0}", "dbFile.sql"))
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
End If
End With
End Function