Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:23:32+00:00 2026-06-12T03:23:32+00:00

I just want to loop through the results in the database. That’s all I

  • 0

I just want to loop through the results in the database. That’s all I am trying to do at this point! This is the error I get when I try to debug:

A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 – Error Locating Server/Instance
Specified)

It points to this line:

// fill dataset into named table
myAdapter.Fill(myDataSet, "Sent");

Here is my whole code:

    // get connection strings from app.config
    string conString = ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;

    // connection object
    SqlConnection myConn = new SqlConnection(conString);

    // create adapter
    SqlDataAdapter myAdapter = new SqlDataAdapter("select * from `Sent`", myConn);

    // create command builder
    SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);

    // create dataset
    DataSet myDataSet = new DataSet();

    // fill dataset into named table
    myAdapter.Fill(myDataSet, "Sent");

    // query using linq
    IEnumerable<DataRow> results
        = from row in myDataSet.Tables["Sent"].AsEnumerable()
          select row;

    // enumerate through results
    foreach (DataRow row in results)
    {
        MessageBox.Show(row.ToString());
    }

What can I do to fix this? Also, if anyone has an easier way to use databases in C#, I am open to your ideas because this has been ridiculous for me (manipulating a database in c#). Thank you for your help.

Update 6/29/12:

The following code works for me:

        // get connection strings from app.config
        string conString = ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;

        // connection object
        SqlCeConnection myConn = new SqlCeConnection(conString);

        // create adapter
        SqlCeDataAdapter myAdapter = new SqlCeDataAdapter("select * from [Sent]", myConn);

        // create command builder
        SqlCeCommandBuilder myCommandBuilder = new SqlCeCommandBuilder(myAdapter);

        // create dataset
        DataSet myDataSet = new DataSet();

        // fill dataset into named table
        myAdapter.Fill(myDataSet, "Sent");

        // create new row
        DataRow newRow = myDataSet.Tables["Sent"].NewRow();

        // set field vals
        newRow["sendTo"] = sendTo;
        newRow["subject"] = subject;
        newRow["message"] = message;

        // add new row to table
        myDataSet.Tables["Sent"].Rows.Add(newRow);

        // update database
        myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
        int updatedRows = myAdapter.Update(myDataSet, "Sent");
        //MessageBox.Show("There were "+updatedRows.ToString()+" updated rows");

        // close connection
        myConn.Close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:23:34+00:00Added an answer on June 12, 2026 at 3:23 am

    I wasn’t using the correct code (it didn’t have anything to do with any connection stuff). This was my first crack at trying to connect to a database in a language other than PHP. Now, I would probably use LINQ or Lambda expressions than this code. But here is what I used which worked:

        // get connection strings from app.config
        string conString = ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
    
        // connection object
        SqlCeConnection myConn = new SqlCeConnection(conString);
    
        // create adapter
        SqlCeDataAdapter myAdapter = new SqlCeDataAdapter("select * from [Sent]", myConn);
    
        // create command builder
        SqlCeCommandBuilder myCommandBuilder = new SqlCeCommandBuilder(myAdapter);
    
        // create dataset
        DataSet myDataSet = new DataSet();
    
        // fill dataset into named table
        myAdapter.Fill(myDataSet, "Sent");
    
        // create new row
        DataRow newRow = myDataSet.Tables["Sent"].NewRow();
    
        // set field vals
        newRow["sendTo"] = sendTo;
        newRow["subject"] = subject;
        newRow["message"] = message;
    
        // add new row to table
        myDataSet.Tables["Sent"].Rows.Add(newRow);
    
        // update database
        myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
        int updatedRows = myAdapter.Update(myDataSet, "Sent");
        //MessageBox.Show("There were "+updatedRows.ToString()+" updated rows");
    
        // close connection
        myConn.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am tempted to loop through the results and just add it to the
I have a hash of values that I am trying to loop through to
Is it faster to do a single database query that finds all the results
Just want to ask can netbean IDE get connected to clearcase remote client server
I just want to ask if anybody has done something like this. Basically, it's
I just want to ask if is it okay that I use native PHP
I have a while loop that goes through a table and I echo the
I am trying to write my first WCF Service. Right now I just want
I built a quick program that needed to loop through an enormous log file
Or is there ? I just have int[] results and want to check each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.