I have my database linked to my project and I am trying to view my database data in a data grid view. My database is written in sql server and My code is
SqlCommand^ myCommand = gcnew SqlCommand("SELECT * FROM CSC 289.Customer WHERE Customer_ID = '" + grid + "';", myCon);
SqlDataReader^ myReader;
try {
myCon->Open();
myReader = myCommand -> ExecuteReader();
if (myReader -> Read()){
String^ ID = myReader -> GetString("Customer_ID");
txtID -> Text = ID;
/*String^ NameVal = myReader -> GetString("Customer_Name");
txtName -> Text = NameVal;
String^ PhoneVal = myReader -> GetString("Customer_Phone");
txtPhone -> Text = PhoneVal;
String^ EmailVal = myReader -> GetString("Customer_Email");
txtEmail -> Text = EmailVal;*/
}
}
catch (Exception^ ex) {
MessageBox::Show(ex->Message);
}
}
The errors I receive when I try and run my program are
error C2664: 'System::String ^System::Data::Common::DbDataReader::GetString(int)' : cannot convert parameter 1 from 'const char [12]' to 'int'
and
function "System::Data::SqlClient::SqlDataReader::GetString" cannot be called with the given argument list argument types are: (const char [12]) object type is: System::Data::SqlClient::SqlDataReader ^
I am not sure how to fix my problem and help would be great.