“SELECT * FROM book WHERE year=wyear AND account >= waccount1 AND account <= waccount1” - mysql

For several days I've been struggling to display data from the table in DataSet. When I do not put a condition in the WHERE, it displays the complete table, but only the rows in the table that meet the condition are required. If there are suggestions for a quicker view. Thanks a lot.
myConnectionString = pwput;
MySqlConnectionconpara = new MySql.Data.MySqlClient.MySqlConnection();
conpara.ConnectionString = myConnec DataSetionString;
try
{
conpara.Open();
if (conpara.State == ConnectionState.Open)
{
string waccoun1 = wnalog1.ToString();
string waccoun2 = wnalog2.ToString();
stringnupita = "SELECT * FROM book WHERE year=wyear AND account >=
waccount1 AND account <= waccount1";
MySqlCommandcmdnal = new MySqlCommand(nupita,conpara);
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#year",
wyear);
MySqlDataAdapte radda = new MySqlataAdapter(cmdnal);
MySqlCommandBuildercbb = new MySqlCommandBuilder(adda);
DataSet dsd = new DataSet();
adda.Fill(dsd, "book");
conpara.Close();
if (dsd != null)
{
dataGridView1.DataSource = dsd;
dataGridView1.DataMember = "book";
Font = new System.Drawing.Font("Arial Unicode", 7);
dataGridView1.Font = Font;
{

You need to use parameters like so:
...
stringnupita = "SELECT * FROM book WHERE year=#year AND account >=
#waccount1 AND account <= #waccount2";
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#year",
wyear);
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#waccount1",
waccount1);
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#waccount2",
waccount2);
...

Related

how to use for loop to read data from mysql table

I have mysql Database and i want to read data from there in my web application with for loop instead of foreach loop.
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
string query = "SELECT * FROM survey ORDER BY datetime DESC";
MySqlCommand com = new MySqlCommand(query, conn);
com.CommandTimeout = 0;
MySqlDataAdapter da = new MySqlDataAdapter(com);
DataTable ds = new DataTable();
da.Fill(ds);
conn.Close();
foreach (DataRow item in ds.Rows)
{
string unique = item.ItemArray[4].ToString();
var sur = db2.VoipSurveys.Where(a => a.UniqueId == unique).SingleOrDefault();
if (sur == null)
{
VoipSurvey vs = new VoipSurvey()
{
Date = Convert.ToDateTime(item.ItemArray[1]),
Point = Convert.ToInt32(item.ItemArray[2]),
CallerId = item.ItemArray[3].ToString(),
UniqueId = item.ItemArray[4].ToString(),
AgentNumber = item.ItemArray[5].ToString(),
AgentName = item.ItemArray[6].ToString(),
QueueNumber = item.ItemArray[7].ToString()
};
db2.VoipSurveys.Add(vs);
db2.SaveChanges();
}
}
I need reading data from specific index like reading data in mysql table from this Date until now. and i think my problem would be solved with for loop
You can use a DataView RowFilter also:
// Create a DataView
DataView dv = new DataView(dt);
dv.RowFilter = " (Date >= #" +
Dateyouwanttouse +
"# And Date <= #" +
DateTime.Now +
"# ) ";
Simply do this:
foreach (DataRowView rowView in dv)
{
DataRow row = rowView.Row;
// Do something //
}

Exchange Webservice get meeting ID from list of availability

I'm creating appointments like
Appointment appointment = new Appointment(service);
appointment.Subject = m.Subject;
appointment.Start = m.StartTime;
appointment.End = m.EndTime;
appointment.StartTimeZone = TimeZoneInfo.Utc;
appointment.EndTimeZone = TimeZoneInfo.Utc;
....
appointment.Save(folder, SendInvitationsMode.SendToNone);
I can then retrieve the CalIdVal
My system lists out appointments for users. I get this using
GetUserAvailabilityResults results = service.GetUserAvailability(attendees, tw, AvailabilityData.FreeBusyAndSuggestions);
I'd like to filter out the appointment created above.
But this list doesn't contain any IDs so I can't see how.
Any advice appreciated
You need to set the FreeBusyViewType in you GetUserAvailability to Detailed https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.freebusyviewtype?view=exchange-ews-api then you should get back a list of HexEntryId's for the appointments which you then can convert to EWSId so you can bind/filter eg
DateTime StartTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 0:00"));
DateTime EndTime = StartTime.AddDays(1);
TimeWindow tmTimeWindow = new TimeWindow(StartTime, EndTime);
AvailabilityOptions aoOptions = new AvailabilityOptions();
aoOptions.RequestedFreeBusyView = Microsoft.Exchange.WebServices.Data.FreeBusyViewType.DetailedMerged;
aoOptions.MeetingDuration = 30;
List<AttendeeInfo> atAttendeeList = new List<AttendeeInfo>();
atAttendeeList.Add(new AttendeeInfo("user#domain.com"));
GetUserAvailabilityResults avResponse = service.GetUserAvailability(atAttendeeList, tmTimeWindow, AvailabilityData.FreeBusy, aoOptions);
Int32 atnCnt = 0;
foreach (AttendeeAvailability avail in avResponse.AttendeesAvailability)
{
Console.WriteLine(atAttendeeList[atnCnt].SmtpAddress);
Int32 mc = 0;
var merged = avail.MergedFreeBusyStatus;
while (StartTime < EndTime)
{
Console.WriteLine(StartTime.ToString() + " " + merged[mc]);
mc++;
StartTime = StartTime.AddMinutes(30);
}
foreach (Microsoft.Exchange.WebServices.Data.CalendarEvent calendarItem in avail.CalendarEvents)
{
Console.WriteLine("Free/busy status: " + calendarItem.FreeBusyStatus);
Console.WriteLine("Start time: " + calendarItem.StartTime);
Console.WriteLine("End time: " + calendarItem.EndTime);
var convertedId = (AlternateId)service.ConvertId(new AlternateId(IdFormat.HexEntryId, calendarItem.Details.StoreId, "someemail#domain.com"), IdFormat.EwsId);
var apt = Appointment.Bind(service, new ItemId(convertedId.UniqueId));
}
atnCnt++;
}

asp.net with mysql Unknown column in where clause

enter code here string customerName = Request.Form[txtSearch.UniqueID];
string customerId = Request.Form[hfCustomerId.UniqueID];
Label1.Enabled = true;
Label1.Text = customerName;
DataRow dr = GetData("SELECT * FROM actor where first_name = " +txtSearch.Text.ToString() ).Rows[0];
Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);
Is there any problem with mysql syntax?
Correct me if i am going wrong.
While i am searching with a specified value, this runs perfectly. But creating problem when trying to pass a value.
try this:
DataRow dr = GetData("SELECT * FROM actor where first_name = '" +txtSearch.Text+"' ).Rows[0];

SQL searching daily attributes error

I am trying to build an application which searches all attributes step by step daily and monthly using the between statement. The daily queries run, but monthly dones't run.
The code:
if (libs.conn.con.State == ConnectionState.Closed) libs.conn.baglanti.Open();
string today = "select getdate()";
SqlCommand today1 = new SqlCommand(today, libs.conn.con);
string today2 = today1.ExecuteScalar().ToString();
string[] day = today2.Split(' ');
day[0] += " 00:00:00";
string dayy = (DateTime.Now.Day).ToString();
string month = (DateTime.Now.Month).ToString();
string year = (DateTime.Now.Year).ToString();
string[] combine = new string[] { "1." };
combine[0] += month + ".";
combine[0] += year + " ";
combine[0] += "00:00:00";
string totalmonth = "(SELECT SUM(para) FROM statistics where datee between '"+combine[0]+"' AND '"+today2+"')";
SqlCommand totalmoneymonthlyquery = new SqlCommand(totalmoneymonth, libs.conn.baglanti);
string totalmoneymonthlyresult = totalmoneymonthlyquery.ExecuteScalar().ToString();
textBox7.Text = totalmoneymonthlyresult.ToString();
use
combine[0]=today2
use first
you may get parameter error to pull data.
String.Format("{0:d/M/yyyy HH:mm:ss}", dt);
String.Format("{0:d/M/yyyy HH:mm:ss}", dt);

not compiling the product expression in DataColumn showing error as "Cannot find column [max]."

While running the code it is giving error " Cannot find column [max]." but i have added the max and min column to the table in the dataset
MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(GetConnectionString());
if (mycon.State != ConnectionState.Open)
{
string sqlCat = "SELECT * FROM out_of_mark_table";
string sqlProd = "SELECT * FROM scord_mark_table";
MySqlDataAdapter da = new MySqlDataAdapter(sqlCat, mycon);
DataSet ds = new DataSet();
try
{
mycon.Open();
da.Fill(ds, "out_of_mark_table");
da.SelectCommand.CommandText = sqlProd;
da.Fill(ds, "scord_mark_table");
}
finally
{
mycon.Close();
}
DataRelation relat = new DataRelation("CatProds", ds.Tables["out_of_mark_table"].Columns["test_id"], ds.Tables["scord_mark_table"].Columns["test_id"]);
ds.Relations.Add(relat);
DataColumn count = new DataColumn("Products (#)", typeof(int), "COUNT(Child(CatProds).test_id)");
DataColumn max = new DataColumn("Most Expensive Product", typeof(decimal), "MAX(Child(CatProds).total)");
DataColumn min = new DataColumn("Least Expensive Product", typeof(decimal), "MIN(Child(CatProds).total)");
DataColumn no=new DataColumn("No");
DataColumn IdCol = new DataColumn();
min.Caption = "min";
max.Caption = "max";
string expr = "max * min";
IdCol.ColumnName = "ID";
IdCol.DataType = Type.GetType("System.Int32");
IdCol.ReadOnly = true;
IdCol.AllowDBNull = false;
//IdCol.Unique = true;
IdCol.AutoIncrement = true;
IdCol.AutoIncrementSeed = 1;
IdCol.AutoIncrementStep = 1;
ds.Tables["out_of_mark_table"].Columns.Add(count);
ds.Tables["out_of_mark_table"].Columns.Add(max);
ds.Tables["out_of_mark_table"].Columns.Add(min);
ds.Tables["out_of_mark_table"].Columns.Add(IdCol);
DataColumn sum = new DataColumn("Sum of", typeof(int), expr, MappingType.Attribute);
**ds.Tables["out_of_mark_table"].Columns.Add(sum);**
IdCol.SetOrdinal(0);
GridView1.DataSource = ds.Tables["out_of_mark_table"];
GridView1.DataBind();
You have set the captions to "Max" and "Min", but the DataColumns's identifier is it's Ordinal or ColumnName. You have set the ColumnName via constructor to
"Most Expensive Product" and "Least Expensive Product"
So use
string expr = "[Most Expensive Product] * [Least Expensive Product]";
instead.