|
Hello,
I'm having a few issues with my code, i'm following this tutorial http://www.homeandlearn.co.uk/csharp/csharp_s12p6.html Can anyone point me in the right direction. I've included my code below.
The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, System.Data.SqlClient.SqlConnection)
<pre lang="c#">Argument 2: cannot convert from 'System.Data.SqlServerCe.SqlCeConnection' to 'System.Data.SqlClient.SqlConnection'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Game
{
public partial class Form1 : Form
{
public OpenFileDialog dialog = new OpenFileDialog();
System.Data.SqlServerCe.SqlCeConnection con;
System.Data.SqlServerCe.SqlCeDataAdapter da1;
DataSet ds1;
public Form1()
{
InitializeComponent();
}
private void btn_sel_Click(object sender, EventArgs e)
{
dialog.ShowDialog();
MessageBox.Show(dialog.FileName);
loadconnection();
}
private void btn_close_Click(object sender, EventArgs e)
{
Application.Exit();
}
public void loadconnection()
{
con = new System.Data.SqlServerCe.SqlCeConnection();
con.ConnectionString = "Data Source=" + dialog.FileName + "";
con.Open();
ds1 = new DataSet();
string sql = "SELECT * From tbl_games";
da1 = new System.Data.SqlClient.SqlDataAdapter(sql, con);
da1.Fill(ds1, "Name");
con.Close();
}
}
}
|
|
|
|
|
antrock101 wrote: da1 = new System.Data.SqlClient.SqlDataAdapter(sql, con);
You have defined dal to be of type SqlCeDataAdapter .
You cannot assign it to an instance of SqlDataAdapter .
Thus you get an error.
Use one type of data adapter and there should be no error.
|
|
|
|
|
Thank you
I've entered
da1 = new System.Data.SqlServerCe.SqlCeConnection(sql,con);
Which appears to work however it requires a function that contains 2 arguments and i'm not entirely sure what it's trying to reference
|
|
|
|
|
|
I have, but i'm having trouble getting this to work
|
|
|
|
|
And you think we can guess what trouble that is? Please show the exact code you are using and what errors you receive. If you look closely at the link I gave you it shows exactly what parameters are required by the constructor. Have you done it correctly?
|
|
|
|
|
No. You havent done what Abinav suggested to you.
public partial class Form1 : Form
{
public OpenFileDialog dialog = new OpenFileDialog();
System.Data.SqlServerCe.SqlCeConnection con;
System.Data.SqlServerCe.SqlCeDataAdapter da1;
DataSet ds1;
public Form1()
{
InitializeComponent();
}
private void btn_sel_Click(object sender, EventArgs e)
{
dialog.ShowDialog();
MessageBox.Show(dialog.FileName);
loadconnection();
}
private void btn_close_Click(object sender, EventArgs e)
{
Application.Exit();
}
public void loadconnection()
{
con = new System.Data.SqlServerCe.SqlCeConnection();
con.ConnectionString = "Data Source=" + dialog.FileName + "";
con.Open();
ds1 = new DataSet();
string sql = "SELECT * From tbl_games";
da1 = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, con);
da1.Fill(ds1, "Name");
con.Close();
}
}
Try the above modified code.
BTW: are you writing the above program for WindowsCE device?
Jibesh V P
|
|
|
|
|
You're trying to mix and match similarly named classes from System.Data.SqlServerCe and System.Data.SqlClient namespaces. Understand which platform you're targeting and use the appropriate namespace for the platform.
|
|
|
|