How do I read data from sql query and insert the result into a ListDictionary?


hi,

i have table looking this:

userid uniqueidentifier unchecked
firstname nchar(20) unchecked
lastname nchar(20) unchecked
birthdate datetime unchecked
address nvarchar(100) unchecked
mobile nchar(12) unchecked
city nchar(20) unchecked
country nchar(20) unchecked
username nchar(20) checked


i can insert data , update not fetch 1 row.
i have 1 subroutine called getuserfromdb(string user).
it supposed return listdictonary of user request. i.e 1 row of table.

the problem userid uniqueidentifier (not allowed change this) , sqldatareader not type.
when execution comes line while (reader.read()) fowwloing exception:

[system.data.sqlclient.sqlexception] = {"conversion failed when converting character string uniqueidentifier."}

how can work around problem?


here code:

using (sqlconnection mysqlconnection = new sqlconnection(connectionstring))
{

sqlcommand mysqlcommand = new sqlcommand(querystring, mysqlconnection);
mysqlcommand.connection.open();
sqldatareader reader = mysqlcommand.executereader();
listdictionary dicta = new listdictionary();
while (reader.read())
{
for (int lp = 0; lp < reader.fieldcount; lp++)
{
dicta.add(reader.getname(lp), reader.getvalue(lp));
}
}
mysqlconnection.close();

return dicta;
}

br mat

fault found.

 

connectionstring poining old db same name different data.

 

br mat

 



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user