C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-23-2009, 01:14 AM   #1
Registered User
 
Join Date: Aug 2009
Posts: 1
The ConnectionString property has not been initialized.

I'm trying to write a registration form in windows application and insert the information to a SQL Database !

I got this error ! :

************** Exception Text **************
System.InvalidOperationException: The ConnectionString property has not been initialized.
at System.Data.Common.DbDataAdapter.UpdatingRowStatus Errors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at FingerAppNet.Register.btnRegister_Click(Object sender, EventArgs e) in C:\******\Register.cs:line 114 ( This Line : da.Update(ds1, "Reg"); )

Here's my code :

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;      // For the database connections and objects.
using System.Data.Common;
using System.Configuration;

namespace FingerAppNet
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }

        System.Data.SqlClient.SqlConnection con;

        int MaxRows = 0;
        int inc = 0;

        private void Register_Load(object sender, EventArgs e)
        {
            con = new System.Data.SqlClient.SqlConnection();
Source=|DataDirectory|\\Reg.mdf";
            ds1 = new DataSet();
            con.ConnectionString ="Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Reg.mdf;Integrated Security=True;User Instance=True";
            string sq1 = "SELECT * FROM RegisterUser";
            da = new System.Data.SqlClient.SqlDataAdapter(sq1, con);
            con.Open();
            da.Fill(ds1, "Reg");

            con.Close();
            con.Dispose();
        }

private void btnRegister_Click(object sender, EventArgs e)
        {

            if (tbtPassword.Text != tbtConfirmPassword.Text)
            {
                MessageBox.Show("passwords are not Match!");

            }
            else
            {
                MessageBox.Show("The details are fine");

                System.Data.SqlClient.SqlCommandBuilder cb;
                cb = new System.Data.SqlClient.SqlCommandBuilder(da);
                DataRow dRow = ds1.Tables["Reg"].NewRow();

                dRow[1] = tbtUserName.Text;
                dRow[2] = tbtPassword.Text;
                dRow[3] = tbtConfirmPassword.Text;
                dRow[4] = tbtImage.Text;

                ds1.Tables["Reg"].Rows.Add(dRow);

                MaxRows = MaxRows + 1;
                inc = MaxRows - 1;

                da.Update(ds1, "Reg");

                MessageBox.Show("added");

            }

        }
Can someone tell me how to fix it ?

Last edited by shembelcut; 08-23-2009 at 01:17 AM.
shembelcut is offline   Reply With Quote
Old 08-23-2009, 11:40 AM   #2
WDT
Tha 1 Sick RAT
 
Join Date: Dec 2003
Posts: 267
Code:
con.ConnectionString =@"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Reg.mdf;Integrated Security=True;User Instance=True";
I haven't read your whole code but this might be the problem. The @ should prevent you needing to escape everything

Also
Code:
Source=|DataDirectory|\\Reg.mdf";
has a typo here. You're missing a ".
__________________
A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

Last edited by WDT; 08-23-2009 at 12:13 PM.
WDT is offline   Reply With Quote
Reply

Tags
c# sql, sql

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
static property George2 C# Programming 1 06-12-2008 01:03 AM
Screwy Linker Error - VC2005 Tonto C++ Programming 5 06-19-2007 02:39 PM
C++/CLI Property psychopath Windows Programming 5 07-11-2006 09:45 PM
Problem with a file parser. Hulag C++ Programming 7 03-17-2005 09:54 AM
Property Sheets :: MFC kuphryn Windows Programming 0 05-09-2002 03:04 PM


All times are GMT -6. The time now is 01:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22