Click here to Skip to main content
15,914,943 members
Home / Discussions / C#
   

C#

 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 15:19
emma.sun.sts28-Nov-13 15:19 
SuggestionRe: Excel file creation and saving in Windows Service doesn't work. Pin
Eddy Vluggen28-Nov-13 10:16
professionalEddy Vluggen28-Nov-13 10:16 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 14:46
emma.sun.sts28-Nov-13 14:46 
Questionguidance on supplying credentials to the server via sockets for login to the server Pin
Arjun Mourya27-Nov-13 1:56
Arjun Mourya27-Nov-13 1:56 
AnswerRe: guidance on supplying credentials to the server via sockets for login to the server Pin
Nicholas Marty27-Nov-13 3:59
professionalNicholas Marty27-Nov-13 3:59 
AnswerRe: guidance on supplying credentials to the server via sockets for login to the server Pin
Dave Kreskowiak27-Nov-13 5:11
mveDave Kreskowiak27-Nov-13 5:11 
AnswerRe: guidance on supplying credentials to the server via sockets for login to the server Pin
Eddy Vluggen27-Nov-13 7:11
professionalEddy Vluggen27-Nov-13 7:11 
Questionc# listview Pin
Member 1026351927-Nov-13 1:46
Member 1026351927-Nov-13 1:46 
hi am developing c# winforms application.
my requirement is basedon tag_id(sEPC) ,i need to get the data from inventory table and populate that data(tagid,categoryid,productid,productname,gateid and remarks) on listview

next check the transaction table whether the out time is null. if out_time is null ,then update the record using tag_id.
if not null then insert the new record in transaction table.
here is the code:

string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'";
MySqlCommand cmd;
MySqlDataReader rdr;
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();

// DataTable dt = new DataTable();
cmd = new MySqlCommand(query, connection);
rdr = cmd.ExecuteReader();
/*Received Epc matched in the Inventory Table */
if (rdr != null)
{
String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim();
// ListView1_EPC.Items[j].Remove();
if (rdr.Read())
{
String a1;

cnt = ListView1_EPC.Items.Count;
ListViewItem item = new ListViewItem(rdr.GetString(0));
// cnt = ListView1_EPC.Items.Count;

item.SubItems.Add(rdr.GetString(1));
item.SubItems.Add(rdr.GetString(2));
item.SubItems.Add(rdr.GetString(3));
item.SubItems.Add(rdr.GetString(4));
item.SubItems.Add("");
item.SubItems.Add("");
item.SubItems.Add(rdr.GetString(5));

//item.SubItems[Remarks.Index].Text = rdr.GetString(5);
ListView1_EPC.Items.Add(item);
rdr.Close();
cnt = ListView1_EPC.Items.Count;
MessageBox.Show("cnt:"+cnt);
string query1 = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM transaction where tag_id Like '" + sEPC + "' AND out_time=NULL";
MySqlCommand cmd1 = new MySqlCommand(query1, connection);
MySqlDataReader rdr1 = cmd1.ExecuteReader();
if (rdr1 == null)
{
item.SubItems[INTime.Index].Text = s2;
//String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,out_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[INTime.Index].Text.Trim() + "','" + item.SubItems[OUTTime.Index].Text + "','" + item.SubItems[Remarks.Index].Text.Trim() + "')";
// MySqlCommand cmd;
String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[INTime.Index].Text.Trim() + "','" + item.SubItems[Remarks.Index].Text.Trim() + "')";
MySqlConnection connection1 = new MySqlConnection(MyConnectionString);
cmd = new MySqlCommand(str, connection1);
connection1.Open();

testret = cmd.ExecuteNonQuery();
}
else
{
item.SubItems[OUTTime.Index].Text = s2;
String str = "update transaction set out_time='" + item.SubItems[OUTTime.Index].Text + "' where tag_id='" + ListView1_EPC.Items[i].Text + "' ";
// String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,out_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[INTime.Index].Text.Trim() + "','" + item.SubItems[OUTTime.Index].Text + "','" + item.SubItems[Remarks.Index].Text.Trim() + "')";
// String str = "insert into transaction(tag_id,out_time)values('" + sEPC + "','" + item.SubItems[OUTTime.Index].Text + "')";
MySqlConnection connection1 = new MySqlConnection(MyConnectionString);
cmd = new MySqlCommand(str, connection1);
connection1.Open();

testret = cmd.ExecuteNonQuery();
}



}//if
while excecution.am getting the error as:
InvalidArgument=Value of '20' is not valid for 'index'.
Parameter name: index

in update query.
plz help me......
there is no index 20 in listview.
my listview is having just:

tagid,categoryid,productid,productname,gateid,intime,outtime,remarks.
GeneralRe: c# listview Pin
harold aptroot27-Nov-13 4:54
harold aptroot27-Nov-13 4:54 
AnswerRe: c# listview Pin
Eddy Vluggen27-Nov-13 7:20
professionalEddy Vluggen27-Nov-13 7:20 
GeneralRe: c# listview Pin
Member 1026351927-Nov-13 19:11
Member 1026351927-Nov-13 19:11 
GeneralRe: c# listview Pin
Eddy Vluggen28-Nov-13 9:35
professionalEddy Vluggen28-Nov-13 9:35 
QuestionC# code to relate two nodes Pin
AshwiniSH26-Nov-13 19:33
professionalAshwiniSH26-Nov-13 19:33 
AnswerRe: C# code to relate two nodes Pin
Bernhard Hiller26-Nov-13 21:11
Bernhard Hiller26-Nov-13 21:11 
GeneralRe: C# code to relate two nodes Pin
AshwiniSH26-Nov-13 21:59
professionalAshwiniSH26-Nov-13 21:59 
AnswerRe: C# code to relate two nodes Pin
OriginalGriff26-Nov-13 23:13
mveOriginalGriff26-Nov-13 23:13 
AnswerRe: C# code to relate two nodes Pin
Richard MacCutchan27-Nov-13 0:28
mveRichard MacCutchan27-Nov-13 0:28 
QuestionMatrices and moving objects in Unity3D c# Pin
begginerc226-Nov-13 3:57
begginerc226-Nov-13 3:57 
SuggestionRe: Matrices and moving objects in Unity3D c# Pin
Richard MacCutchan26-Nov-13 5:54
mveRichard MacCutchan26-Nov-13 5:54 
QuestionGetting a value from one method to another method Pin
Member 982953626-Nov-13 2:16
Member 982953626-Nov-13 2:16 
AnswerRe: Getting a value from one method to another method Pin
OriginalGriff26-Nov-13 2:36
mveOriginalGriff26-Nov-13 2:36 
GeneralRe: Getting a value from one method to another method Pin
Member 982953626-Nov-13 3:17
Member 982953626-Nov-13 3:17 
GeneralRe: Getting a value from one method to another method Pin
GuyThiebaut26-Nov-13 3:48
professionalGuyThiebaut26-Nov-13 3:48 
GeneralRe: Getting a value from one method to another method Pin
OriginalGriff26-Nov-13 3:52
mveOriginalGriff26-Nov-13 3:52 
AnswerRe: Getting a value from one method to another method Pin
Richard MacCutchan26-Nov-13 2:46
mveRichard MacCutchan26-Nov-13 2:46 

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.