Start New Discussion within our Software Development Community

Hello i'm getting theses to error with my sql code can anyone help me ot at all i'm really lost and can't find much to help where i'm going wrong.Code is below

Error   3   The best overloaded method match for 'System.Data.SqlClient.SqlCommandBuilder.SqlCommandBuilder(System.Data.SqlClient.SqlDataAdapter)' has some invalid arguments   

Error   4   Argument 1: cannot convert from 'System.Data.SqlServerCe.SqlCeDataAdapter' to 'System.Data.SqlClient.SqlDataAdapter'    

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 tb_name : Form
        public OpenFileDialog dialog = new OpenFileDialog();
        System.Data.SqlServerCe.SqlCeConnection con;
        System.Data.SqlServerCe.SqlCeDataAdapter da1;

        DataSet ds1;

        public int romowned;
        public int ownedgame;

        int MaxRows = 0;
        int inc = 0;

        public tb_name()

        private void btn_sel_Click(object sender, EventArgs e)
            DataRow dRow = ds1.Tables["Name"].Rows[inc];

        private void btn_close_Click(object sender, EventArgs e)

        public void Loadconnection()
            con = new System.Data.SqlServerCe.SqlCeConnection();
            con.ConnectionString = "Data Source=" + dialog.FileName + ""; //opening dialog (selected file)


            ds1 = new DataSet();
            string sql = "SELECT * From tbl_games";
            da1 = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, con);
            da1.Fill(ds1, "Name");


        public void NavigateRecords()
            DataRow dRow = ds1.Tables["Name"].Rows[0];
            tbname.Text = dRow.ItemArray.GetValue(1).ToString();
            tbcompany.Text = dRow.ItemArray.GetValue(3).ToString();
            tbregion.Text = dRow.ItemArray.GetValue(4).ToString();
            tbyear.Text = dRow.ItemArray.GetValue(2).ToString();
            tbentry.Text = dRow.ItemArray.GetValue(7).ToString();

            string owned = dRow.ItemArray.GetValue(5).ToString();
            string rom = dRow.ItemArray.GetValue(6).ToString();

            if (owned == null || owned == String.Empty & chxowned.Checked)
                ownedgame = 1;
                dRow[5] = ownedgame;   

            if (rom == null || rom == String.Empty & chxowned.Checked)
                romowned = 1; 
                dRow[6] = romowned;


        private void tbnew_Click(object sender, EventArgs e)
            chxowned.Checked = false;
            chxrom.Checked = false;

        private void tbsave_Click(object sender, EventArgs e)

            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da1);

            DataRow dRow = ds1.Tables["Name"].NewRow();
            dRow[1] = tbname.Text;
            dRow[3] = tbcompany.Text;
            dRow[4] = tbregion.Text;
            dRow[2] = tbyear.Text;
            dRow[7] = tbentry.Text;
            dRow[5] = romowned;
            dRow[6] = ownedgame;

            da1.Update(ds1, "Name");

            romowned = 0;
            ownedgame = 0;


On line 22 you have a SqlCeDataAdapter..

 System.Data.SqlServerCe.SqlCeDataAdapter da1;

and on line 110 you are trying to create an instance of SqlCommandBuilder

System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da1);

An sql compact db is not the same as another type of db. You are trying to instansiate a SqlCommandBuilder object whilst passing it a SqlCeDataAdapter. You cannot do this. You need to pass a SqlCeDataAdapter to a SqlCeCommandBuilder.

System.Data.SqlServerCe.SqlCeDataAdapter da1;

System.Data.SqlServerCe.SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da1);
This article has been dead for over six months. Start a new discussion instead.