|
Thanks christian
Excuse my lack of experience with this Christian but how do I apply this to all the values in my datatable.
I also forgot to say that all of the columns have a header row that has to remain as a string, so i guess what i have to do is cycle through all the individual cells in the datatable and convert the ones that can be converted with TryParse, is this correct ? and if so how would i approach this.
thanks again
|
|
|
|
|
minnie mouse,
To convert every string in your database to an int you must iterate thru every row and change the value in each column to a int.
For example if you have grabbed all data from your database and have filled your dataset with this data. Use the code below check for syntax errors.
But this should get you going.
DataTable table = MyDataSet.Tables[0];
foreach(DataRow row in table.Rows)
{
foreach(DataColumn column in table.Columns)
{
int newIntValue = int.Parse(row[column].toString());
row[column] = newIntValue;
}
}
In your database you must be sure to change the dataType of the column so that when you update your database with the dataset via dataAdapter you get no dataType errors.
|
|
|
|
|
Thanks for this help, please see Christians comments
Much clearer now.
|
|
|
|
|
minnie mouse wrote: Excuse my lack of experience with this Christian but how do I apply this to all the values in my datatable.
Your core problem is that your database design is wrong. As it stands, you need to create a new column in your datatable, and copy the values across using SQL. Then delete the old table. I'm not sure that you can just change the type of a column.
minnie mouse wrote: I also forgot to say that all of the columns have a header row that has to remain as a string,
Is this a database we're talking about ? A header is obvioulsy a string. It's the name of the column.
minnie mouse wrote: so i guess what i have to do is cycle through all the individual cells in the datatable and convert the ones that can be converted with TryParse, is this correct ?
To do this in memory, and keep your database in this less than useful format, yes. I think someone else gave you some sample code.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian,
Thanks for your help with this, all the info I have read so far doesnt seem to apply to the situation I have. Which is the need to write a data import programme, therefore the approach most of the educational material i have seen of firstly design the database, then etc , etc cant be applied as i'm starting with nothing but a large amount of csv data.
Ive got to the point where i can succesfully store all this as string data in a SQL database tables. I now need to perform some calculations on the majority of the columns.These columns contain numbers but have names as the first row. I wasnt sure if it was easier to conert to numeric datatype first or try to act on the stored strings in the table with maybe a stored procedure?
Please excuse my lack of understanding of this, i am looking for experienced guidance.
|
|
|
|
|
If you're starting with a CSV, then rewrite your import code to create numeric columns for numeric data. Otherwise, you'll always be held back by poor database design.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks christian
I will now do that. I did wonder at the time if I was going the right way.
Stay tuned for future developments !
Curvoisier concerto is a personal favourite of mine.;)
|
|
|
|
|
You can convert your data on the fly using a cast:
select cast(columnname as int) from ...
|
|
|
|
|
I know you can handle the ItemClick event for each of the menuitems individually. Is it possible to handle all the click events for a menu using a switch statement? If so how?
Mark
|
|
|
|
|
You could assign the same Click event handler for every menu item. The sender in your event handler arguments is the menu item that was clicked, so you can create a switch statement...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
i have a text file i want to read its word and search if it match some keywords saved in access table, i read from file successfully but how can i compare each word in text with each key word in the table, how can i know the frequency for each word in the text
SUMA
|
|
|
|
|
In Java you can set an method to be synchronized. As I'm new to C# i would know how locking works in C#? If any of you knows about book that covers real time programming in C# it would make my day.
|
|
|
|
|
|
You can accomplish the same with something like this:
using System.Runtime.CompilerServices;
...
[MethodImpl(MethodImplOptions.Synchronized)]
void MySychronizedMethod()
{
}
Typically, C# synchronization is done with the lock keyword:
lock(someObj)
{
...
}
|
|
|
|
|
Hi all,
I'm very new to programming in C# (and programming in general). I'm getting "Syntax error in INSERT INTO statement." and I haven't got a clue why.
Here's the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace dbTest
{
public partial class Form1 : Form
{
String conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\MasterInventory2.mdb";
OleDbConnection con = new OleDbConnection();
DataTable dtCardlist = new DataTable();
DataTable dtTemp = new DataTable();
OleDbDataAdapter daCardlist;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.ConnectionString = conString;
daCardlist = new OleDbDataAdapter("Select * From Cardlist", con);
daCardlist.Fill(dtCardlist);
dataGridView1.DataSource = dtCardlist;
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
daCardlist.InsertCommand = con.CreateCommand();
daCardlist.InsertCommand.CommandText = "INSERT INTO Cardlist "+
"(Name, Set, Cost, Type, PowTgh, Rules, Rarity) "+
"VALUES "+
"(?,?,?,?,?,?,?)";
daCardlist.InsertCommand.Connection = con;
daCardlist.InsertCommand.Parameters.Add("Name", OleDbType.Char, 0, "Name");
daCardlist.InsertCommand.Parameters.Add("Set", OleDbType.Char, 0, "Set");
daCardlist.InsertCommand.Parameters.Add("Cost", OleDbType.Char, 0, "Cost");
daCardlist.InsertCommand.Parameters.Add("Type", OleDbType.Char, 0, "Type");
daCardlist.InsertCommand.Parameters.Add("PowTgh", OleDbType.Char, 0, "PowTgh");
daCardlist.InsertCommand.Parameters.Add("Rules", OleDbType.Char, 0, "Rules");
daCardlist.InsertCommand.Parameters.Add("Rarity", OleDbType.Char, 0, "Rarity");
DataRow newRow = dtCardlist.NewRow();
newRow["Name"] = "testCard2";
newRow["Set"] = "TST";
newRow["Cost"] = "Cost";
newRow["Type"] = "Type";
newRow["PowTgh"] = "PowTgh";
newRow["Rules"] = "Rules";
newRow["Rarity"] = "Rarity";
dtCardlist.Rows.Add(newRow);
daCardlist.Update(dtCardlist);
con.Close();
}
}
}
I suspect that it's something really simple, but I just don't see it.
Any help is appreciated.
|
|
|
|
|
"Name" is a reserved word in Access.
"Set" is a reserved word in Access and in OleDb.
---
b { font-weight: normal; }
|
|
|
|
|
I've been looking at the text for two days, and I didn't see THAT!
Anyway, I've changed the "Set" to "Cardset" and everything works perfectly.
Thanks!
|
|
|
|
|
HI . I want to filter the data of a column of an asp grid view on basis of a value given in a text field. These text fields should be visible on top of every column(below the header text). How can i do it? Your response in this regard will be appreciated. Thanks
|
|
|
|
|
Hi!
please tell me hOw we can change Attribute Names of a particular "element" after loading document in XmlDocument class.
Thanks
|
|
|
|
|
Here is a way that keeps the attribute's orignal value and position: There may be a simplier solution.
using System;
using System.Xml;
namespace CSharp
{
class Program
{
static void Main(string[] args)
{
String xml =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<book name='Introduction to C# 2.0'/>";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlElement docElem = xmlDoc.DocumentElement;
XmlAttribute attribName =
xmlDoc.DocumentElement.Attributes["name"];
XmlAttribute attribTitle =
xmlDoc.CreateAttribute("title");
attribTitle.Value = attribName.Value;
docElem.Attributes.InsertBefore(attribTitle, attribName);
docElem.Attributes.Remove(attribName);
Console.WriteLine(xmlDoc.OuterXml);
}
}
}
|
|
|
|
|
hellow to all ..
i am trying to creat a public variable in my forum that i could access it from othere forms ..
but it is not working for me ..
how can i creat it ...
thxx
|
|
|
|
|
The simplest solution is to create a class with a static field in your Forms namespace.
<br />
class MyClass<br />
{<br />
public static int publicVariable = 0;<br />
}<br />
You access the variable above by: MyClass.publicVariable = 10;
|
|
|
|
|
Don't use public variables, use public properties.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
i want the code to enable one button out of three when other two are are disable and vice versa in c#.net
ursbuddy
|
|
|
|
|
That's pretty straightforward. What have you tried ? To tie the three buttons together, you'd need to create a control. It's easier just to write code that enables one button and disables the other two.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|