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()
        {
            InitializeComponent();
        }

        private void btn_sel_Click(object sender, EventArgs e)
        {
            dialog.ShowDialog();
            MessageBox.Show(dialog.FileName);
            Loadconnection();
            NavigateRecords();
            DataRow dRow = ds1.Tables["Name"].Rows[inc];
            con.Close();
            con.Dispose();
        }

        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 + ""; //opening dialog (selected file)

            con.Open();


            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)
        {
            tbcompany.Clear();
            tbentry.Clear();
            tbname.Clear();
            tbregion.Clear();
            tbyear.Clear();
            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;
            ds1.Tables["Name"].Rows.Add(dRow);

            da1.Update(ds1, "Name");

            romowned = 0;
            ownedgame = 0;
        }





    }
}

Can you post the error you're getting?

I'm pretty sure connection string is wrong for a start, have a look at this

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.