Click here to Skip to main content
15,888,020 members
Home / Discussions / Database
   

Database

 
QuestionSudden cast problem using executescalar Pin
Gennady Oster5-Nov-13 22:25
Gennady Oster5-Nov-13 22:25 
AnswerRe: Sudden cast problem using executescalar Pin
Richard Deeming6-Nov-13 1:22
mveRichard Deeming6-Nov-13 1:22 
GeneralRe: Sudden cast problem using executescalar Pin
Gennady Oster6-Nov-13 1:46
Gennady Oster6-Nov-13 1:46 
Questionhow can left join two table on multiple column??? Pin
mhd.sbt5-Nov-13 9:22
mhd.sbt5-Nov-13 9:22 
AnswerRe: how can left join two table on multiple column??? Pin
Richard Deeming5-Nov-13 9:58
mveRichard Deeming5-Nov-13 9:58 
QuestionMysql select query with multiple conditions Pin
Member 102635195-Nov-13 1:50
Member 102635195-Nov-13 1:50 
AnswerRe: Mysql select query with multiple conditions Pin
Richard Deeming5-Nov-13 2:36
mveRichard Deeming5-Nov-13 2:36 
GeneralRe: Mysql select query with multiple conditions Pin
Member 102635195-Nov-13 20:22
Member 102635195-Nov-13 20:22 
thanks for reply.
but am getting fatal error at da.Fill(ds).
and :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(1 = 1) OR tag_id = 'E2002076990B019322902641')' at line 1
here is my code: in button click;

i entered tag_id dynamically

// Connect to Mysql
String query;
System.Data.DataTable dt = new System.Data.DataTable();
String conString = "Server=localhost;Database=asset;Uid=root;pwd=root";
MySqlConnection con = new MySqlConnection(conString);
MySqlCommand command = new MySqlCommand();
command .Connection = new MySqlConnection(conString);
command.CommandType = CommandType.Text;
//command.CommandText =query;
con.Open();
MySqlCommand cmd = new MySqlCommand("set net_write_timeout=99999; set net_read_timeout=99999", con);

string fromDate = dateTimePicker1.Value.ToString("yyyy-MM-dd");
string toDate = dateTimePicker2.Value.ToString("yyyy-MM-dd");
query = "select tag_id,category_id,product_id,product_name,gate_id,in_time,out_time,remarks from transaction where (DATE(in_time)BETWEEN '" + fromDate + "'AND '" + toDate + "')";
if ((R_Tag.Text == "") && (R_Category.Text == "") && (R_Product.Text == "") && (R_ProName.Text == "") && (R_Gate.Text == ""))
{
query = "select tag_id,category_id,product_id,product_name,gate_id,in_time,out_time,remarks from transaction where DATE(in_time)BETWEEN '" + fromDate + "'AND '" + toDate + "' ";
command.CommandText = query;

da = new MySqlDataAdapter(command);
ds = new DataSet();
da.Fill(ds);
//System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);

}
else
{
try
{

var queryBuilder = new StringBuilder();
queryBuilder.Append("select tag_id, category_id, product_id, product_name, gate_id, in_time, out_time, remarks from transaction where DATE(in_time) BETWEEN @FromDate And @ToDate");
command.Parameters.AddWithValue("@FromDate", fromDate);
command.Parameters.AddWithValue("@ToDate", toDate);

queryBuilder.Append("AND (1 = 1");

if (!string.IsNullOrEmpty(R_Tag.Text))
{
queryBuilder.Append(" OR tag_id = @RTag");
command.Parameters.AddWithValue("@RTag", R_Tag.Text);
}
if (!string.IsNullOrEmpty(R_Category.Text))
{
queryBuilder.Append(" OR category_id = @RCategory");
command.Parameters.AddWithValue("@RCategory", R_Category.Text);
}
if (!string.IsNullOrEmpty(R_Product.Text))
{
queryBuilder.Append(" OR product_id = @RProduct");
command.Parameters.AddWithValue("@RProduct", R_Product.Text);
}
if (!string.IsNullOrEmpty(R_ProName.Text))
{
queryBuilder.Append(" OR product_name = @RProName");
command.Parameters.AddWithValue("@RProName", R_ProName.Text);
}
if (!string.IsNullOrEmpty(R_Gate.Text))
{
queryBuilder.Append(" OR gate_id = @RGate");
command.Parameters.AddWithValue("@RGate", R_Gate.Text);
}

queryBuilder.Append(")");
command.CommandText = queryBuilder.ToString();


// command.CommandTimeout = 600;
da = new MySqlDataAdapter(command);
ds = new DataSet();
da.Fill(ds);

da.Fill(dt);
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
} }

modified 6-Nov-13 7:17am.

GeneralRe: Mysql select query with multiple conditions Pin
Richard Deeming6-Nov-13 1:08
mveRichard Deeming6-Nov-13 1:08 
GeneralRe: Mysql select query with multiple conditions Pin
Member 102635196-Nov-13 1:38
Member 102635196-Nov-13 1:38 
GeneralRe: Mysql select query with multiple conditions Pin
Richard Deeming6-Nov-13 1:54
mveRichard Deeming6-Nov-13 1:54 
GeneralRe: Mysql select query with multiple conditions Pin
Member 102635196-Nov-13 18:10
Member 102635196-Nov-13 18:10 
GeneralRe: Mysql select query with multiple conditions Pin
Member 102635196-Nov-13 19:41
Member 102635196-Nov-13 19:41 
Questionunique random alphanumeric in MySQL Pin
Jassim Rahma5-Nov-13 0:14
Jassim Rahma5-Nov-13 0:14 
AnswerRe: unique random alphanumeric in MySQL Pin
thatraja5-Nov-13 2:17
professionalthatraja5-Nov-13 2:17 
AnswerRe: unique random alphanumeric in MySQL Pin
jschell5-Nov-13 9:09
jschell5-Nov-13 9:09 
GeneralRe: unique random alphanumeric in MySQL Pin
Jassim Rahma19-Jul-14 7:03
Jassim Rahma19-Jul-14 7:03 
QuestionUsing SQL LocalDB Pin
GenJerDan29-Oct-13 3:56
GenJerDan29-Oct-13 3:56 
AnswerRe: Using SQL LocalDB Pin
Richard Deeming29-Oct-13 4:51
mveRichard Deeming29-Oct-13 4:51 
GeneralRe: Using SQL LocalDB Pin
GenJerDan29-Oct-13 4:57
GenJerDan29-Oct-13 4:57 
QuestionSQL connection in Visual studio 2012 Pin
Member 1017436328-Oct-13 7:47
Member 1017436328-Oct-13 7:47 
QuestionRe: SQL connection in Visual studio 2012 Pin
Eddy Vluggen28-Oct-13 8:44
professionalEddy Vluggen28-Oct-13 8:44 
AnswerRe: SQL connection in Visual studio 2012 Pin
Member 1017436328-Oct-13 21:08
Member 1017436328-Oct-13 21:08 
AnswerRe: SQL connection in Visual studio 2012 Pin
Richard Deeming28-Oct-13 12:40
mveRichard Deeming28-Oct-13 12:40 
AnswerRe: SQL connection in Visual studio 2012 Pin
Bernhard Hiller29-Oct-13 22:02
Bernhard Hiller29-Oct-13 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.