473,487 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Connection Property has not been initialized

1 New Member
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient; 
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.  
  16.         public Form1()
  17.         {
  18.  
  19.             InitializeComponent();
  20.  
  21.         }
  22.  
  23.         private void maskedTextBox2_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  24.         {
  25.  
  26.         }
  27.  
  28.         System.Data.SqlClient.SqlConnection con;
  29.         DataSet ds1;
  30.         System.Data.SqlClient.SqlDataAdapter da;
  31.         int MaxRows = 0;//defined for the next button interface work
  32.         int inc = 0;//defined for the next button interface work 
  33.         private void Form1_Load(object sender, EventArgs e)
  34.         {
  35.             con = new System.Data.SqlClient.SqlConnection();
  36.             ds1 = new DataSet();
  37.  
  38.             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";
  39.             con.Open();
  40.             string sql = "SELECT * From PHYTONTB1";
  41.             da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
  42.             da.Fill(ds1, "Workers");
  43.             NavigateRecords();
  44.             MaxRows = ds1.Tables["Workers"].Rows.Count;//MaxRows will contain a count of how many Rows are in the Dataset called ds1.
  45.             con.Close();
  46.  
  47.  
  48.             con.Dispose();
  49.  
  50.  
  51.         }
  52.         private void NavigateRecords()
  53.         {
  54.         DataRow dRow=ds1.Tables["Workers"].Rows[inc];//default value inc=0 point to 0 for next button used 
  55.         maskedTextBox2.Text = dRow.ItemArray.GetValue(1).ToString();
  56.         maskedTextBox3.Text = dRow.ItemArray.GetValue(2).ToString();
  57.         maskedTextBox4.Text = dRow.ItemArray.GetValue(3).ToString();
  58.         maskedTextBox5.Text = dRow.ItemArray.GetValue(4).ToString();
  59.  
  60.         }
  61.  
  62.         private void groupBox1_Enter(object sender, EventArgs e)
  63.         {
  64.  
  65.         }
  66.  
  67.         private void button7_Click(object sender, EventArgs e)
  68.         {
  69.             if (inc > 0)// Back interface control when you push geri button it will decrease one row from Database
  70.             {
  71.                 inc--;//decrease inc value
  72.                 NavigateRecords();//this method used for taking ready data from dataset to form why we called
  73.             }
  74.             else
  75.             {
  76.                 MessageBox.Show("ilk kayıt");
  77.             }
  78.         }
  79.  
  80.         private void maskedTextBox3_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  81.         {
  82.  
  83.         }
  84.  
  85.         private void maskedTextBox4_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  86.         {
  87.  
  88.         }
  89.  
  90.         private void maskedTextBox5_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  91.         {
  92.  
  93.         }
  94.  
  95.         private void maskedTextBox6_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  96.         {
  97.  
  98.         }
  99.  
  100.         private void textBox1_TextChanged(object sender, EventArgs e)
  101.         {
  102.  
  103.         }
  104.  
  105.         private void button6_Click(object sender, EventArgs e)
  106.         {
  107.             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 
  108.             {
  109.                 inc++;//if cond satisfied increment 1 for next button
  110.                 NavigateRecords();//this method used for taking ready data from dataset to form why we called 
  111.             }
  112.             else
  113.             {
  114.                 MessageBox.Show("son kayıt");
  115.             }
  116.  
  117.         }
  118.  
  119.         private void button4_Click(object sender, EventArgs e)
  120.         {
  121.             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 
  122.             {
  123.                 inc = 0;
  124.                 NavigateRecords();
  125.             }
  126.             MessageBox.Show("bilgi! Bu sizin Kaydettiğiniz İlk Kayıttır");
  127.         }
  128.  
  129.         private void button3_Click(object sender, EventArgs e)
  130.         {
  131.             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
  132.             {
  133.                 inc = MaxRows - 1;
  134.                 NavigateRecords();
  135.             }
  136.             MessageBox.Show("bilgi! Bu sizin Kaydettiğiniz Son Kayıttır");
  137.         }
  138.  
  139.         private void btnAddNew_Click(object sender, EventArgs e)
  140.         {
  141.             maskedTextBox2.Clear();
  142.             maskedTextBox3.Clear();
  143.             maskedTextBox4.Clear();
  144.             maskedTextBox5.Clear();
  145.  
  146.         }
  147.  
  148.         private void btnSave_Click(object sender, EventArgs e)
  149.         {
  150.            System.Data.SqlClient.SqlCommandBuilder cb;
  151.            cb = new System.Data.SqlClient.SqlCommandBuilder(da);
  152.  
  153.            DataRow dRow = ds1.Tables["Workers"].NewRow();
  154.  
  155.            dRow[1]= maskedTextBox2.Text;
  156.            dRow[2]= maskedTextBox3.Text;
  157.            dRow[3]= maskedTextBox4.Text;
  158.            dRow[4]= maskedTextBox5.Text;
  159.  
  160.            ds1.Tables["Workers"].Rows.Add(dRow);
  161.  
  162.            MaxRows = MaxRows + 1;
  163.            inc = MaxRows - 1;
  164.  
  165.            da.Update(ds1, "Workers");//THİS LİNE GİVES ERROR Connection Property has not been initialized
  166.            MessageBox.Show("SUCCESS!!!!");
  167.  
  168.  
  169.         }
  170.     }
  171. }
Oct 27 '09 #1
2 3423
tlhintoq
3,525 Recognized Expert Specialist
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.
Oct 27 '09 #2
Markus
6,050 Recognized Expert Expert
Furthermore, do you have a question? Please see the forum guidelines on How To Ask A Question.
Oct 27 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
38504
by: GrantS | last post by:
I am unable to get the connection to work with using the app.config file. the connection works when I use 'in line' connection as below:...
2
11576
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated...
2
1179
by: Tim::.. | last post by:
Can someone tell me what is wrong with the sub below??? I'm try to create a bunch of SQL connections on the fly... I'm sure there is a better way to do this but was having problem with the sql...
9
1421
by: Taishi | last post by:
ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
3
9061
by: Jason Williard | last post by:
I am trying to create a web form that will be used to create new users. The first step that I am taking is creating a web form that can check the username against a database to see if it already...
4
4040
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
7
33523
by: Lawrence 007 | last post by:
Hi, I am new to VB.Net and I am trying to create a program that inserts data into a SQL table. Below you will find my code that gives me the following error: Connection Property has not been...
2
1557
by: nada111 | last post by:
SelectCommand.Connection property has not been initialized
2
3628
by: gggram2000 | last post by:
Hi, I'm using visual studio 2005 with sql server 2005. I made a program on my computer that works great. I wanted to transfer the same project through a remote connection to another computer, I...
0
5336
by: santiago8000 | last post by:
hello,i'm new to vb.net,and i'm trying to do my first program for my training...my program is about the Northwind2 database in sql server,i have a "ShowAll" button,that displays in a form the...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.