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 ?