We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,661 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

C# SQL issue

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;
        }





    }
}
3
Contributors
3
Replies
1 Day
Discussion Span
4 Months Ago
Last Updated
27
Views
antrock101
Newbie Poster
2 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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

ChrisHunter
Posting Pro
566 posts since Feb 2011
Reputation Points: 104
Solved Threads: 51
Skill Endorsements: 13

Errors on the top of the page, I followed a tutorial
http://web.archive.org/web/20121016092446/http://homeandlearn.co.uk/csharp/csharp_s12p10.html

I'vehad it working before years ago can't remember how tho. I usally work locally not in forms

antrock101
Newbie Poster
2 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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);
james6754
Posting Whiz in Training
221 posts since Dec 2010
Reputation Points: 50
Solved Threads: 21
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0865 seconds using 2.72MB