J
jerrylinkinpark
Guest
Hi guys,
I am trying to write a Windows Form Application in Visual Studio 2017 regarding a database. I have created a local database file and also added a SQL query file which intent to add one row in this database. I have experience with C++ before, so the Windows form part is not so difficult to me.
But now, I don't know how to establish the Connection between the C++ program and the database. There are some examples in Internet but only in C# or VB which doesn't help so much. Can anyone help me a bit or give me a hint which direction should i go..
I have tried to transfer one C# code into C++ as following
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try
{
String^ str = "Data Source=(local); Database=mydata;";
String^ query = "select * from data";
SqlConnection^ con = gcnew SqlConnection(str);
SqlCommand^ cmd = gcnew SqlCommand(query, con);
con->Open();
DataSet^ ds = gcnew DataSet();
MessageBox::Show("connect with sql server");
con->Close();
}
catch (Exception^)
{
MessageBox::Show("Error!");
}
}
But when I click this button, it still shows Error Message. Can anyone help?
Thanks in Advance!
Continue reading...
I am trying to write a Windows Form Application in Visual Studio 2017 regarding a database. I have created a local database file and also added a SQL query file which intent to add one row in this database. I have experience with C++ before, so the Windows form part is not so difficult to me.
But now, I don't know how to establish the Connection between the C++ program and the database. There are some examples in Internet but only in C# or VB which doesn't help so much. Can anyone help me a bit or give me a hint which direction should i go..
I have tried to transfer one C# code into C++ as following
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try
{
String^ str = "Data Source=(local); Database=mydata;";
String^ query = "select * from data";
SqlConnection^ con = gcnew SqlConnection(str);
SqlCommand^ cmd = gcnew SqlCommand(query, con);
con->Open();
DataSet^ ds = gcnew DataSet();
MessageBox::Show("connect with sql server");
con->Close();
}
catch (Exception^)
{
MessageBox::Show("Error!");
}
}
But when I click this button, it still shows Error Message. Can anyone help?
Thanks in Advance!
Continue reading...