seek some help

Hello , This is my first database App.
I'm trying to export data from table in SQLServer to ListView in VS2010
I'm getting errors C2664 and C2228 (String^ name,price) lines below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

String^ conString = "data source=.; database = Myproject; integrated security = SSPI";

 SqlConnection^ connection = gcnew SqlConnection(conString);

 SqlCommand^ cmd = gcnew SqlCommand("SELECT [Name],[Price]FROM [MyProject].[dbo].[tblShisha]", connection);

 try
{
     connection->Open();
      SqlDataReader^ reader = cmd->ExecuteReader();

	while(reader->Read())
	{

	 String^ name = reader->GetString("Name").ToString();
	String^ price = reader->GetFloat("Price").ToString();
	ListViewItem^ item = gcnew ListViewItem (name);
	item->SubItems->Add(price);
	listView1->Items->Add(item);	
	}


}catch(Exception^ e)
 {
MessageBox::Show("Error importing Data from Shisha Table");
 }
 finally
 {
connection->Close();
 }


Could you help and clarify your solution please.
Google is your friend.

C2664 'function' : cannot convert parameter number from 'type1' to 'type2'
http://msdn.microsoft.com/en-us/library/s5b150wd.aspx
This indicates a type mismatch on the argument to GetString and GetFloat.
GetString and GetFloat take an int, not a column name.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getstring.aspx

C2228 left of '.identifier' must have class/struct/union
http://msdn.microsoft.com/en-us/library/3y365xw6(v=vs.90).aspx
GetFloat returns a native float, not a String^. Therefore, it has no ToString method.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getfloat.aspx

In the future, please post the full text of any error messages.
Last edited on
"In the future, please post the full text of any error messages." is the best advice in the post you know :D.
. ThankYou.
Topic archived. No new replies allowed.