Error in VB.NET mysqldump export with two conditions - mysql

I have a problem exporting my desired output. I want to use 'AND' in the where clause but it's not working. But when I use only one of the condition ex. --where=clientid='" + clientid + "', it's working. But when I add status='', its not working anymore. What is my error here? Thanks!
Code:
Sub Export()
Dim file As String
Dim clientid = frmDashboard.txtClientID.Text
SaveFileDialog1.Filter = "SQL Dump File (*.sql)|*.sql|All files (*.*)|*.*"
SaveFileDialog1.FileName = "CUST" + clientid + ".sql"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
file = SaveFileDialog1.FileName
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.WorkingDirectory = "C:\Program Files\MySQL\MySQL Server 5.7\bin"
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
Dim status = ""
myStreamWriter.WriteLine("mysqldump -u administrator --password=password --skip-add-drop-table --no-create-info -h localhost cashloan clientcustomers --where=clientid='" + clientid + "' and status=''> " + file + " ") 'clientcustomers --where=clientid=" + clientid + "
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
MsgBox("Export was finished successfully.", MsgBoxStyle.Information, "Export")
End If
End Sub

got it. I added double quotes.
--where=""status='" + status + "' and clientid='" + clientid + "'""

Related

how to display 2 tables from mysql in visual studio 17

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

asp.net:query with multiple where conditions

1. I have query.But couldn't add second where condition.Please suggest me the correct semantic .
2. And how can fetch the data from dropdownlist and show it in gridview.
3. How can i fetch value from Tution fee Column of my database when condition satisfies ,and Hostel Fee on fail of condition.??
protected void BindGridview()
{
constr = ConfigurationManager.ConnectionStrings["connstring_DETMIS"].ToString(); // connection string
// String FID = DropDownList1.SelectedItem.Value;
using (var conn = new MySql.Data.MySqlClient.MySqlConnection(constr)) {
conn.Open();
using (var cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from fees_collect_category" + " where F_id =" + DropDownList1.SelectedItem.Value " and C_id=" + DropDownList2.SelectedItem.Value, conn)) {
using (var reader = cmd.ExecuteReader()) {
if (reader.HasRows) {
gvDetails.DataSource = reader;
gvDetails.DataBind();
} else
lblWarning.Text = "There are no records..";
}
}
}
}
Welcome to Stackoverflow. You should first research on the google as why you are not able to add multiple conditions(It's just because of simple syntax mistake).
The exact code of line would be something like this.
using (var cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from fees_collect_category" +
" where F_id = '" + DropDownList1.SelectedItem.Value + "' and C_id=" + DropDownList2.SelectedItem.Value + "'", conn))
NOTE:- As a fellow developer, I won't suggest you to do this by passing values from here as it is dangerous and prone to SQL INJECTION
I would rather tell you to go by using Parameterized queries
Hope that helps and for future go for the Parametrized ones, as it is easy and technically preffered.
protected void BindGridview()
{
String strConnString = ConfigurationManager
.ConnectionStrings["connstring_DETMIS"].ConnectionString;
String strQuery = "select * from student_details " +
"where F_id=#F_Id and C_id=#C_Id";
MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(strConnString);
MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Parameters.AddWithValue("#F_Id",
DropDownList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("#C_Id",
DropDownList2.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
gvDetails.DataSource = cmd.ExecuteReader();
gvDetails.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}

Exception Thrown in this block thats why page cannot be redirected

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

vb.net, Restore mysql database not working in windows xp

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

CSV file filled in data adapter is empty or not

private DataTable GetDataFromCSV()
{
System.Data.DataTable dtExecChanges = new System.Data.DataTable("exec_changes");
string dirName = Path.GetDirectoryName(sInputFileName);
using (OleDbConnection cn =
new OleDbConnection(#"Provider=Microsoft.Jet.OleDb.4.0;" +
"Data Source=" + dirName + ";" +
"Extended Properties=\"Text;HDR=Yes;FMT=Delimited\""))
{
// Open the connection
cn.Open();
// Set up the adapter
using (OleDbDataAdapter adapter =
new OleDbDataAdapter("SELECT * FROM " + (sInputFileName.Substring(sInputFileName.LastIndexOf("\\") + 1)), cn))
{
adapter.Fill(dtExecChanges);
}
cn.Close();
}
When I fill my data table dtExecChanges it will error coz my CSV file is empty.
Is there a way to chck is the select query is actually fetching any rows b4 filling by data table??