I was Coding a project wich connect and read something from sql database,
PHP Code:
MsSQL my = new MsSQL("select * from TableExample"); using (System.Data.SqlClient.SqlDataReader reader = my.Read()) { while (reader.Read()) { accInformation acc = new accInformation(); Console.WriteLine(reader.GetString("User")); acc.User = reader.GetString("User"); acc.password = reader.GetString("password"); acc.Name = reader.GetString("Name"); acc.Email = reader.GetString("Email"); acc.sex = reader.GetString("sex"); acc.address = reader.GetString("address"); acc.postcode = reader.GetString("postcode"); acc.phone = reader.GetString("phone"); acc.mobile = reader.GetString("mobile"); acc.reg_ip = reader.GetString("reg_ip"); Global.AccountList.Add(acc); max++; } } my.Close();
but
reader.GetString("exmple")
gets an error System.InvalidCastException ,
The Best overloaded method match for system.data.comman.dbdatareader.getstring(int) has some invalid arguments
-------------------------
You should always check the before even asking. The GetString() method obviously expects an integer that specifies the column index.
Instead you are passing strings that aren't even representing numbers, but letters. Which is why trying to cast these strings to integer implicitly will raise an exception.
The solution is rather simple: you should rethink what it is that you are trying to accomplish and then use proper methods.
Put can u write a small explain ^^ about how to change GetString (to gives it int i)
as if u look here
acc.Email = reader.GetString("Email");
and
accInformation acc = new accInformation();
accInformation is class to another item
sorry i'm not as good in english enough to explain what i mean ,
Unfortunately, I haven't worked with SQL and C# myself, so I am probably unable to provide any profound intel on that. Also, giving you any advice on what methods to use would require to actually know how your data is structured.
So I'd suggest you explain a little more thoroughly how your SQL data is structured by preferably giving a proper example.
Unfortunately, I haven't worked with SQL and C# myself, so I am probably unable to provide any profound intel on that. Also, giving you any advice on what methods to use would require to actually know how your data is structured.
So I'd suggest you explain a little more thoroughly how your SQL data is structured by preferably giving a proper example.
First thanks for try to help
well let me talk first about my project , it's copy the new data from table(database) 2 to table 1
so we can say we got mssql1 and mssql2 , mssql = the first users table
mssql 2 = the secound users table (the tables got the same name and same content [content like struserid, password, Email, etc..])
mssql1 is the original users table so mssql1 refers to a mssql1.cs (i mean to another content) that contain the read module
and mssql2.cs that contain more then modul reader like write and clean and some more .
If u need more info just tell me
ah(about MsSQL it's refers to mssql1 as i name them mssql and mssql1)
Here is the suggestion from Muddy_Waters in code. Just name the columns in the SQL statement and use to column indices with GetString(). Also check if every column is of type string.
PHP Code:
MsSQL my = new MsSQL("select User,password, Name,Email,sex,address,postcode,phone,mobile,reg_ip from TableExample");
using (System.Data.SqlClient.SqlDataReader reader = my.Read())
{
while (reader.Read())
{
accInformation acc = new accInformation();
if (!reader.IsDBNull(0)) {
acc.User = reader.GetString(0);
}
if (!reader.IsDBNull(1)) {
acc.password = reader.GetString(1);
}
[EP2] Shop System Error! 11/17/2011 - Last Chaos - 3 Replies Hey,
habt ihr auch immer System Error, wenn ihr den Shop öffnet? Da kommt nur so ein Fenster System Error und mir wird angezeigt, dass ich 0 Cash habe! Bei meinen ganzen Kumpels ist das auch so! Aber hab zum Test mal 'nen neuen Acc erstellt und bei dem geht es! Wisst ihr wie man das fixen kann?
MfG
System Error in [EG]?? 03/25/2011 - 4Story - 17 Replies Hey,
jetz um 2:10 wurde ich gekickt und hab versucht mich wieder einzuloggen dann stad da : System Error. Please try it again later. Was heißt das??
Thx an alle die es mir sagen können :D
@Krakatoas
Ich spiele 4story^^ aber egal^^ Ok Seite 5----> Tut mir leid aber habe ich nciht sehen können^^ naja gut ich kümmer mich drum
[Error] V 16 Map System 03/20/2011 - Flyff Private Server - 2 Replies Hey, habe keine ahnung wieso, meine neuz das v16 Map System nicht annehmen will :s
Nunja hier ist mein source von Zeile 167- 172 aus..
CWndButton* pWndMonsterInfoCheckBox = ( CWndButton* )GetDlgItem( WIDC_CHECK_MONSTER_INFORMATION );
CWndButton* pWndMonsterInfoCheckBox = ( CWndButton* )GetDlgItem( WIDC_BUTTON_MONSTER_INFO );
{
pWndMonsterInfoCheckBox->SetVisible( TRUE );
}
}
4Story EG ! System Error 09/29/2010 - 4Story - 2 Replies Mein Problem ist ich logge mich mit meine acc ein und dann der 1te cha geht aber bei meinen 2-3-4 wenn ich damit rein will kriege ich kick und steht system error mein lvl 72er ist auch dabei gestern habe ich noch gespielt -.-
Weis jemand eine Lösung?
system.mrs error 03/23/2008 - GunZ - 0 Replies Hey guys how is it going i was doing a tut on system.mrs i did all the editing and started the game and i wonts to update the file/delete my work. how can you do this how do you get past the updating part thx. :)