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
Code:
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.