Jump to content

Search the Community

Showing results for tags 'default null'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. Hai... iam new for C# ...im learning ..i created a table and showing it...now i want to update,edit and delete the records...i did it in my way...Problem is whenever i give save ,addnew or delete button it shows "Object reference not set to an instance of an object."this error at line 120 " cb.DataAdapter.Update(ds1.Tables["workers"]);"my program. using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms; namespace naag_database{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Data.SqlServerCe.SqlCeConnection con; System.Data.SqlServerCe.SqlCeDataAdapter da; DataSet ds1; int MaxRows = 0; int inc = 0; private void Form1_Load(object sender, EventArgs e) { con = new System.Data.SqlServerCe.SqlCeConnection(); con.ConnectionString = "DataSource=C:\\Users\\g.nagaraj\\Documents\\Databases\\naag.sdf"; con.Open(); System.Data.SqlServerCe.SqlCeDataAdapter da; string sql = "SELECT*from tbl_naag"; da = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, con); ds1 = new DataSet(); MessageBox.Show("Connection Open"); da.Fill(ds1, "workers"); //GridItemCollection.Datasource = ds1; //GridItemCollection.Databind(); NavigateRecords(); MaxRows = ds1.Tables["Workers"].Rows.Count; con.Close(); } private void NavigateRecords() { DataRow dRow = ds1.Tables["Workers"].Rows[inc]; textBox1.Text = ds1.Tables["Workers"].Rows[inc].ItemArray.GetValue(4).ToString(); textBox2.Text = ds1.Tables["Workers"].Rows[inc].ItemArray.GetValue(3).ToString(); textBox3.Text = ds1.Tables["Workers"].Rows[inc].ItemArray.GetValue(2).ToString(); textBox4.Text = ds1.Tables["Workers"].Rows[inc].ItemArray.GetValue(1).ToString(); } private void btnNext_Click(object sender, EventArgs e) { if(inc !=MaxRows-1) { inc++; NavigateRecords(); } else { MessageBox.Show("No more Rows"); } } private void btnPrevious_Click(object sender, EventArgs e) { if (inc > 0) { inc--; NavigateRecords(); } else { MessageBox.Show("First Record"); } } private void btnLast_Click(object sender, EventArgs e) { if (inc != MaxRows - 1) { inc = MaxRows - 1; NavigateRecords(); } else { MessageBox.Show("Last record"); } } private void btnFirst_Click(object sender, EventArgs e) { if (inc != 0) { inc = 0; NavigateRecords(); } } private void btnNew_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); btnNew.Enabled =false; btnSave.Enabled =true; } private void updateDB() { System.Data.SqlServerCe.SqlCeCommandBuilder cb; cb = new System.Data.SqlServerCe.SqlCeCommandBuilder(da); cb.DataAdapter.Update(ds1.Tables["workers"]); } private void btnSave_Click(object sender, EventArgs e) { DataRow dRow = ds1.Tables["Workers"].NewRow(); dRow[4] = textBox1.Text; dRow[3] = textBox2.Text; dRow[2] = textBox3.Text; dRow[1] = textBox4.Text; ds1.Tables["Workers"].Rows.Add(dRow); updateDB(); MaxRows = MaxRows + 1; inc = MaxRows - 1; btnNew.Enabled = true; btnSave.Enabled = false; } private void btnupdate_Click(object sender, EventArgs e) { DataRow dRow2 = ds1.Tables["workers"].Rows[inc]; dRow2[4] = textBox1.Text; dRow2[3] = textBox2.Text; dRow2[2] = textBox3.Text; dRow2[1] = textBox4.Text; updateDB(); MessageBox.Show("Data Updated"); } private void btndelete_Click(object sender, EventArgs e) { } private void label5_Click(object sender, EventArgs e) { } private void labelUpdate() { label4.Text = "Record " + (inc + 1) + " of " + MaxRows; } } }
×
×
  • Create New...