Thank you guys... I did what Luc said and it worked.
kallileo
Posts
-
Problem with while loop and text file -
Problem with while loop and text fileI have 2 text files. input1.txt: 560-005;CORFU_1B;560-005-011 560-005;CORFU_1E;560-005-012 560-005;CORFU_1Z;560-005-013 560-005;CORFU_1H;560-005-014 560-005;SENSE_2B;560-005-021 input2.txt 562-Z21;METAL-ANTHRACITE;562-121-000 562-Z21;METAL-9007;562-221-000 562-Z22;METAL-ANTHRACITE;562-122-000 562-Z22;METAL-9007;562-222-000
public void Conversion()
{
try
{
using (sr1 = new StreamReader("c:\\input1.txt"))
{
using (sr2 = new StreamReader("c:\\input2.txt"))
{
file = new FileStream("c:\\output.txt", FileMode.Create, FileAccess.Write);
sw = new StreamWriter(file);
string line1;
string line2;while ((line1 = sr1.ReadLine()) != null) { string\[\] temp1 = line1.Split(new char\[\] { ';' }); while ((line2 = sr2.ReadLine()) != null) { string\[\] temp2 = line2.Split(new char\[\] { ';' }); string final = temp1\[0\] + ";" + temp1\[1\] + ";" + temp1\[2\] + ";" + temp2\[2\] + ";" + temp1\[2\] + "-" + temp2\[2\]; sw.WriteLine(final); } } } } } finally { sr1.Close(); sr2.Close(); sw.Close(); file.Close(); } }
I have created the above method to do some string management. The problem is that the outer while loops runs only for the first line in input1.txt and I don't know why. It's probably something simple but I can't find the solution. Thanks...
-
Read specific cells in ExcelIs it possible to read a specific cell or a range of cells from a spreadsheet document? Thank you
-
Inserting Data from other Database FileI use code to insert data from a mdb file into another using the Merge() method of a DataSet...But it's not very effective in terms of performance. Is it possible to use a sql query to directly insert the data? I don't know how to create the code to link the databases.
public void MergeTables(string connS1, string connS2) { string connString1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS1; string connString2 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS2; OleDbConnection oleConn1 = new OleDbConnection(connString1); OleDbConnection oleConn2 = new OleDbConnection(connString2); string cmd1 = "SELECT *FROM db1_table1"; string cmd2 = "SELECT *FROM db2_table1"; OleDbDataAdapter da1 = new OleDbDataAdapter(cmd1, oleConn1); OleDbDataAdapter da2 = new OleDbDataAdapter(cmd2, oleConn2); DataSet ds1 = new DataSet(); da1.Fill(ds1, "db1_table1"); da2.Fill(ds1, "db2_table1"); ds1.Tables["db1_table1"].Merge(ds1.Tables["db2_table1"]); foreach (DataRow row in ds1.Tables["db1_table1"].Rows) row.SetAdded(); OleDbCommandBuilder cmdBld = new OleDbCommandBuilder(da1); da1.UpdateCommand = cmdBld.GetUpdateCommand(); @da1.Update(ds1, "db1_table1"); }
Thank you :-D -
Problem with merging 2 DataTablesFound it.. The problem was that after the Merge none of the rows in data table had the state RowState Changed or Added. The update methon had nothing to apply. This peace of code made the whole class work as it should:
foreach (DataRow row in ds1.Tables["db2_table1"].Rows) row.SetAdded();
Thanks -
Problem with merging 2 DataTablesNothing yet... public void MergeTables(string connS1, string connS2) { string connString1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS1; string connString2 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS2; OleDbConnection oleConn1 = new OleDbConnection(connString1); OleDbConnection oleConn2 = new OleDbConnection(connString2); string cmd1 = "SELECT *FROM db1_table1"; string cmd2 = "SELECT *FROM db2_table1"; da1 = new OleDbDataAdapter(cmd1, oleConn1); da2 = new OleDbDataAdapter(cmd2, oleConn2); ds1 = new DataSet(); da1.Fill(ds1, "db1_table1"); da2.Fill(ds1, "db2_table1"); ds1.Tables["db1_table1"].Merge(ds1.Tables["db2_table1"]); OleDbCommandBuilder cmdBld = new OleDbCommandBuilder(da1); da1.UpdateCommand = cmdBld.GetUpdateCommand(); @da1.Update(ds1, "db1_table1"); ds1.AcceptChanges(); }
-
Problem with merging 2 DataTablesI tried to create a OleDbCommandBuilder but it still didn't work... OleDbCommandBuilder cmdBld = new OleDbCommandBuilder(da1);
-
Problem with merging 2 DataTablesI have tried both...still doens't work. :^)
-
Problem with merging 2 DataTablesI'm trying merge DataTable "db2_table1" into to DataTable "db1_table1". But it doen't seem to work. Any help will be appreciated....
public class MergeTableClass { private OleDbDataAdapter da1, da2; private DataSet ds1; public void MergeTables(string connS1, string connS2) { string connString1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS1; string connString2 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connS2; OleDbConnection oleConn1 = new OleDbConnection(connString1); OleDbConnection oleConn2 = new OleDbConnection(connString2); string cmd1 = "SELECT *FROM db1_table1"; string cmd2 = "SELECT *FROM db2_table1"; da1 = new OleDbDataAdapter(cmd1, oleConn1); da2 = new OleDbDataAdapter(cmd2, oleConn2); ds1 = new DataSet(); da1.Fill(ds1,"db1_table1"); da2.Fill(ds1,"db2_table1"); ds1.Tables["db1_table1"].Merge(ds1.Tables["db2_table1"]); da1.Update(ds1,"db2_table1"); ds1.AcceptChanges(); } }
-
DataGridView problemI create a DataSet with 4 tables in it from a mdb file using the Wizard of the VS Express 2008. I have a DataGridView and I display the data of the "Transaction" table. I also have a table with my suppliers called "Suppliers". In "Transaction" table I have a column called "Supplier". I have enabled the options to add,edit or delete record in the DataSet and to save all the changes back to the mdb file. To provide an easier way for the user to add new records I set "Supplier" columnType in the DataGridView as DataGridViewComboBoxColumn and DisplayMember, DataSource and ValueMember to the "Name" column in the Supplier table so the user can directly select the name name of the supplier without having to type it. So when I run the program and load the form I get the following error message: System.ArgumentException: DataGridViewComboBoxCell value is not valid. Any help would be appreciated.... Thank you
-
Problem with ComboBox Selected.ItemOk. I have tried some things and this what I get... Using the below code and I have also display member, value member and SelectedValue of the comBox set to Name. private void button3_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Magazi.mdb"); conn.Open(); OleDbCommand cmd = new OleDbCommand("DELETE FROM Suppliers WHERE Name=@Name", conn); OleDbParameter parDel = new OleDbParameter(); parDel.ParameterName = "@Name"; parDel.Value = comboBox1.SelectedValue.ToString(); cmd.Parameters.Add(parDel); cmd.ExecuteNonQuery(); conn.Close(); } When I try to select a value from comboBox I get this message: Column 'Name' is constrained to be unique. Value 'Champion' is already present.
-
Problem with ComboBox Selected.ItemI have a ComboBox that is populated with values from a MS Access table. Next I use the below code to delete the record that is selected in the comboBox. private void button3_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Magazi.mdb"); conn.Open(); OleDbCommand cmd = new OleDbCommand("DELETE FROM Suppliers WHERE Name=@Name", conn); OleDbParameter parDel = new OleDbParameter(); parDel.ParameterName = "@Name"; parDel.Value = comboBox1.SelectedItem; cmd.Parameters.Add(parDel); cmd.ExecuteNonQuery(); conn.Close(); } For some reason I get an "OleDbException was unhandled" message...
-
Updating mdb file from another mdb fileNot yet...but I will. I am still learning. :laugh: Thank you
-
Updating mdb file from another mdb fileI have two Access mdb files with identical table structure...I need to insert records that do exist in the firtst from the second mdb file. What is the appropriate and the best way to do it? Working with dataset maybe? Thank you
-
Help with SQL ParameterI tried the below query SELECT COUNT(*) AS Expr1 FROM data WHERE (timestamp > 19 / 08 / 2007) AND (timestamp < 23 / 08 / 2007) manually but got 0 The column is 19/8/2007 10:25:40 am 19/8/2007 10:25:59 am 20/8/2007 6:10:56 am 20/8/2007 6:11:49 am 20/8/2007 6:20:20 am 20/8/2007 6:20:32 am 20/8/2007 6:20:38 am
-
Help with SQL ParameterYes I found it few minute later...Thanks But now I get another error. protected void Button_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=opc;Integrated Security=True"); conn.Open(); SqlCommand selCmd = new SqlCommand("SELECT COUNT(*) FROM data WHERE timestamp>@date1 AND timestamp<@date2", conn); SqlParameter param1 = new SqlParameter(); SqlParameter param2 = new SqlParameter(); param1.ParameterName = "@date1"; param1.Value = TextBox1.Text; selCmd.Parameters.Add(param1); param2.ParameterName = "@date2"; param2.Value = TextBox2.Text; selCmd.Parameters.Add(param2); int count = (int)selCmd.ExecuteScalar(); Label1.Text = count.ToString(); conn.Close(); } I get this Sql Exception: Arithmetic overflow error converting expression to data type datetime. In line "int count = (int)selCmd.ExecuteScalar();" I need to count the rows between these two dates...
-
Help with SQL ParameterWhat am I doing wrong? SqlConnection conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=opc;Integrated Security=True"); conn.Open(); SqlCommand selCmd = new SqlCommand("SELECT COUNT(*) FROM data WHERE timestamp>@pdate1 AND timestamp<@pdate2", conn); SqlParameter date1 = new SqlParameter(); date1.ParameterName = @pdate1; date1.Value = TextBox1.Text; SqlParameter date2 = new SqlParameter(); date2.ParameterName = @pdate2; date2.Value = TextBox2.Text; selCmd.Parameters.Add(date1); selCmd.Parameters.Add(date2); int count = (int)selCmd.ExecuteScalar(); Label1.Text = count.ToString(); conn.Close(); I get 2 errors: Error 1 The name 'pdate1' does not exist in the current context Error 2 The name 'pdate2' does not exist in the current context
-
Access table to XML [modified]I have extracted some Outlook contacts to Access table and I now I want to create a xml document that has the below structure. I'm thinking of loading the data to a recordset and then to stream it to an XML document. The problem is how could I define the structure I need for my xml document. Could the xml Microsoft XMLDOM object have as parameter a xml style sheet file....or what? Thank you Leonidas Kallis KundenListe> Kunde> KundenDaten> Anschrift> AdrAnrede s="Κύριος"/> AdrName s="Παππας"/> AdrVorname1 s="Ιωάννης"/> AdrStadt s="Δρυός"/> AdrPostfach s="234242"/> AdrTel1 s="210 4428686"/> AdrLand s="GR"/> AdrPlz s="84400"/> /Kunde> /KundenDaten> Kunde> KundenDaten> Anschrift> AdrAnrede s="Κυρία"/> AdrName s="Τρίμμη"/> AdrVorname1 s="Αγαθή"/> AdrStrasse s="Γαμβέττα 43"/> AdrStadt s="Θεσσαλονίκη"/> AdrTel1 s="2310 677933"/> AdrTel2 s="697 χχχ χχχχχ"/> AdrTelefax s="2310 988290"/> AdrLand s="GR"/> /Kunde> /KundenDaten> /KundenListe> -- modified at 4:15 Tuesday 24th July, 2007
-
Convert Null db field to stringm@u wrote:
Hi Since string is a reference type you could also do it like this: string FName = reader["FirstName"] as string; string LName = reader["LastName"] as string; string BPhone = reader["BusinessPhone"] as string; greets M@u
Thanks....
Colin Angus Mackay wrote:
Curiously, if you look at what Convert.ToString actually does, it just boils down to the same as: string FName = reader["FirstName"].ToString(); So, is DBNull.Value.ToString() the value that you really want back?
Yes, it is ok to me...
-
Convert Null db field to stringI think I found it....and it seems to work. But I'm not realy sure if this is the right way to do it. string FName = Convert.ToString(reader["FirstName"]); string LName = Convert.ToString(reader["LastName"]); string BPhone = Convert.ToString(reader["BusinessPhone"]); Thanks -- modified at 9:17 Friday 20th July, 2007 This also works: string BPhone = reader["BusinessPhone"].ToString();