c# & SQL newbie

Discussion in 'C#' started by jat421, Aug 31, 2010.

  1. jat421

    jat421 New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi I am learning to code in C#. But I am stuck at one place. I am trying to connect to SQL server through C#

    I am using VS 2005 and below is the code.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            System.Data.SqlClient.SqlConnection con;
            DataSet ds1;
            System.Data.SqlClient.SqlDataAdapter da;
            DataRow dRow;
    
            private void Form1_Load(object sender, EventArgs e)
            {
                con = new System.Data.SqlClient.SqlConnection();
                ds1 = new DataSet();
                con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\TransNo.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                
                con.Open();
                
                string sql = "SELECT * From tblTransNo";
                da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
    
                da.Fill(ds1, "TransNo");
                NavigateRecords();
                con.Close();
            }
    
            private void NavigateRecords()
            {
                DataRow dRow = dsl.Tables["TransNo"].Rows[0];
    
                textBox1.Text = dRow.ItemArray.GetValue(2).ToString();
            }
        }
    } 
    
    Here are the errors I am getting

    Error 1 The name 'dsl' does not exist in the current context C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\Form1.cs 40 28 WindowsApplication2
    Any help is appreciated.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice