Connection Property has not been initialized | Newbie | | Join Date: Oct 2009
Posts: 1
| | - 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 maskedTextBox2_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
-
{
-
-
}
-
-
System.Data.SqlClient.SqlConnection con;
-
DataSet ds1;
-
System.Data.SqlClient.SqlDataAdapter da;
-
int MaxRows = 0;//defined for the next button interface work
-
int inc = 0;//defined for the next button interface work
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
con = new System.Data.SqlClient.SqlConnection();
-
ds1 = new DataSet();
-
-
con.ConnectionString ="Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Tevhit OKUR\\Belgelerim\\Visual Studio 2010\\Projects\\WindowsFormsApplication1\\WindowsFormsApplication1\\PHYTONDB1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
-
con.Open();
-
string sql = "SELECT * From PHYTONTB1";
-
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
-
da.Fill(ds1, "Workers");
-
NavigateRecords();
-
MaxRows = ds1.Tables["Workers"].Rows.Count;//MaxRows will contain a count of how many Rows are in the Dataset called ds1.
-
con.Close();
-
-
-
con.Dispose();
-
-
-
}
-
private void NavigateRecords()
-
{
-
DataRow dRow=ds1.Tables["Workers"].Rows[inc];//default value inc=0 point to 0 for next button used
-
maskedTextBox2.Text = dRow.ItemArray.GetValue(1).ToString();
-
maskedTextBox3.Text = dRow.ItemArray.GetValue(2).ToString();
-
maskedTextBox4.Text = dRow.ItemArray.GetValue(3).ToString();
-
maskedTextBox5.Text = dRow.ItemArray.GetValue(4).ToString();
-
-
}
-
-
private void groupBox1_Enter(object sender, EventArgs e)
-
{
-
-
}
-
-
private void button7_Click(object sender, EventArgs e)
-
{
-
if (inc > 0)// Back interface control when you push geri button it will decrease one row from Database
-
{
-
inc--;//decrease inc value
-
NavigateRecords();//this method used for taking ready data from dataset to form why we called
-
}
-
else
-
{
-
MessageBox.Show("ilk kayıt");
-
}
-
}
-
-
private void maskedTextBox3_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
-
{
-
-
}
-
-
private void maskedTextBox4_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
-
{
-
-
}
-
-
private void maskedTextBox5_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
-
{
-
-
}
-
-
private void maskedTextBox6_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
-
{
-
-
}
-
-
private void textBox1_TextChanged(object sender, EventArgs e)
-
{
-
-
}
-
-
private void button6_Click(object sender, EventArgs e)
-
{
-
if (inc != MaxRows - 1)//button sonraki MaxRows - 1 It's because of the Rows[inc] line in our NavigateRecords method. The count for Rows starts at zero its for next button
-
{
-
inc++;//if cond satisfied increment 1 for next button
-
NavigateRecords();//this method used for taking ready data from dataset to form why we called
-
}
-
else
-
{
-
MessageBox.Show("son kayıt");
-
}
-
-
}
-
-
private void button4_Click(object sender, EventArgs e)
-
{
-
if (inc != 0)//button ilk kayıt it is checking easly inc value is equal to zero because we should go to the first record if it id not just assigning to inc value to zero can call NavigateRecord method because its creates record on the dataset
-
{
-
inc = 0;
-
NavigateRecords();
-
}
-
MessageBox.Show("bilgi! Bu sizin Kaydettiğiniz İlk Kayıttır");
-
}
-
-
private void button3_Click(object sender, EventArgs e)
-
{
-
if (inc != MaxRows - 1)//button son kayıt it is used for interface last record interface we know that last record in database MaxRow-1 value we just check if not just we assign inc value to MaxRow-1 to equal
-
{
-
inc = MaxRows - 1;
-
NavigateRecords();
-
}
-
MessageBox.Show("bilgi! Bu sizin Kaydettiğiniz Son Kayıttır");
-
}
-
-
private void btnAddNew_Click(object sender, EventArgs e)
-
{
-
maskedTextBox2.Clear();
-
maskedTextBox3.Clear();
-
maskedTextBox4.Clear();
-
maskedTextBox5.Clear();
-
-
}
-
-
private void btnSave_Click(object sender, EventArgs e)
-
{
-
System.Data.SqlClient.SqlCommandBuilder cb;
-
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
-
-
DataRow dRow = ds1.Tables["Workers"].NewRow();
-
-
dRow[1]= maskedTextBox2.Text;
-
dRow[2]= maskedTextBox3.Text;
-
dRow[3]= maskedTextBox4.Text;
-
dRow[4]= maskedTextBox5.Text;
-
-
ds1.Tables["Workers"].Rows.Add(dRow);
-
-
MaxRows = MaxRows + 1;
-
inc = MaxRows - 1;
-
-
da.Update(ds1, "Workers");//THİS LİNE GİVES ERROR Connection Property has not been initialized
-
MessageBox.Show("SUCCESS!!!!");
-
-
-
}
-
}
-
}
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,761
| | | re: Connection Property has not been initialized TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out. |  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Connection Property has not been initialized
Furthermore, do you have a question? Please see the forum guidelines on How To Ask A Question.
| Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,358 network members.
|