Witam,
Podczas proby stworzenia rekordu napotkałem na dziwny bład i nie wiem co mam z tym zrobić mianowicie w zaznaczonych liniach pojawia się bład podczas proby dodania rekordu " Object reference not set to an instance of an object."
Proszę o pomoc bo nie wiem jak sobie z tym poradzic.
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{ System.Data.SqlClient.SqlConnection con;
DataSet ds1;
System.Data.SqlClient.SqlDataAdapter da;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int MaxRows = 0;
int inc = 0;
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = "Data Source=STUDENT-B8BB779\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True";
con.Open();
ds1 = new DataSet();
string sql = "SELECT * From tblUser";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
<b>MaxRows = ds1.Tables["tblUser"].Rows.Count; </b>
<b> DataRow dRow = ds1.Tables["tblUser"].NewRow();</b>
dRow[1] = textBox1.Text;
ds1.Tables["tblUser"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(ds1, "tblUser");
}
}
}
baza wyglada tak :
baza nazywa sie Database1.mdf , w niej jest tabela tblUser a w niej sa 4 pola login , password , ID , time.
Z gory dziękuje za pomoc