![]() |
| | #1 |
| Registered User Join Date: Aug 2009
Posts: 1
| The ConnectionString property has not been initialized. 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");
}
}
Last edited by shembelcut; 08-23-2009 at 01:17 AM. |
| shembelcut is offline | |
| | #2 |
| 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"; Also Code: Source=|DataDirectory|\\Reg.mdf";
__________________ 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 | |
![]() |
| Tags |
| c# sql, sql |
| Thread Tools | |
| Display Modes | |
|
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 |