Results 1 to 4 of 4

Thread: Sql Server Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    58

    Sql Server Problem

    I'm new to C#,but I used VB.NET a lot ... This prject I have to do in C# and I allready have problems connecting to my SQL SERVER Database.

    I put an combobox into my form which I want to link to some records in my database ...

    So combobox.Datasource = ... Add Project DataSource ... Database ... Connection to my SQL SERVER Database ...

    I saved the connection string as TSConnectionString ... Selected the tables and views I need from my database ...

    and Visual Studio has created the files ... TSDataSet.xsd ( TSDataSet.Designer.cs , TSDataSet.xsc , TSDataSet.xss )

    I mention that the combobox.DataSource property is still empty and the program can compile succesfully ... for now

    When I come back to fill combobox.Datasource with TSDataSet namely tSDataSetBindingSource when i try to compile the

    next error message pops up :

    Error 1 The type name 'TSDataSet' does not exist in the type 'TSales.TSales'

    ... and the code behind this error is :


    this.tSDataSet = new TSales.TSDataSet(); --------------- here is the error

    this.tSDataSetBindingSource = new System.Windows.Forms.BindingSource(this.components);
    this.panTop.SuspendLayout();
    ((System.ComponentModel.ISupportInitialize)(this.tSDataSet)).BeginInit();
    ((System.ComponentModel.ISupportInitialize)(this.tSDataSetBindingSource)).BeginInit();
    this.SuspendLayout();


    Remember though I wrote above that Visual Studio creates those 4 files (TSDataSet.xsd , TSDataSet.Designer.cs , TSDataSet.xsc , TSDataSet.xss ) and puts them in Solution Explorer

    So my question is ... how come there is no tSales.TSDataSet ?

    and what should I do to link those records to that combobox and other records to other controls in my form


    Thank you


    PS. I linked the database to a combobox in VB.NET just like I described above and it worked without any problems so it must be a C# problem

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Sql Server Problem

    Oh, yes, it definitely has to be C#. Or is it SQL Server, as your title implies?
    Both languages are based on the CLR and compile to the same IL. It couldn't possibly be something you've done incorrectly or differently. Loving the deductions.

    Open the TSDataSet.Designer.cs file and read the code - take particular note of the namespace, and the generated classes (including nested). What's there? Is there a TSales.TSales.TSDataSet class?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Sql Server Problem

    The issue is that the designer is qualifying the name of the DataSet class with its namespace, i.e. TSales. It is doing so in a class that is also named TSales though, so the compiler is interpreting that qualifier as the current TSales class rather that the TSales namespace.

    This is an example of why you need to take some time and consider naming things descriptively. This is a form class I assume, so the name TSales is quite poor. It should be something like MainForm, MainWindow, SalesForm, SalesWindow, SalesDialogue or the like. Also, TSales is a poor name for a namespace. It is presumably the default namespace name derived from your project name. TSales is also a poor name for a project. You should first of all name your project descriptively, then change the name of your default namespace to something descriptive, then name each class you create descriptively. If you do that then there'll be no name clashes because the names will all naturally be different.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    58

    Resolved Re: Sql Server Problem

    It's done ... I changed the form name from TSales to Main and there are no more errors

    thankyou guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width