Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

SQL Help

$
0
0
Using the following Code, the value returned is System.Data.SqlClient.SqlDataReader rather than the data in the SQL Table. Can someone tell me how to get the data from the table, and why this doesnt work as intended? I am new with connecting C# to SQL so any advise is appreciated.

Code:

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;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            try
            {
                SqlCommand comm = new SqlCommand();
                comm.Connection = new SqlConnection(
                  "Data Source=(local); Integrated Security=SSPI");
                String sql = @"use RAPOS_Replication SELECT * from XmlPartner";
                comm.CommandText = sql;
                comm.Connection.Open();
                SqlDataReader cursor = comm.ExecuteReader();
                while (cursor.Read())
                    label1.Text = (cursor.ToString());
                MessageBox.Show(cursor.ToString());
                comm.Connection.Close();
            }
            catch (Exception error)
            {
                Console.WriteLine(error.ToString());
            }


        }
    }
}


Viewing all articles
Browse latest Browse all 42215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>