Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NullReferenceException object reference not set to an instance of an object..please help

NullReferenceException object reference not set to an instance of an object..please help

Scheduled Pinned Locked Moved C#
databasehelpgraphicssysadminsecurity
6 Posts 4 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bobolov
    wrote on last edited by
    #1

    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; using Microsoft.AnalysisServices; using Microsoft.DataWarehouse.Interfaces; using System.Data.OleDb; using System.Data.Common; namespace DatabaseApplication { public partial class Form1 : Form { string dbname; string connectionstring; string databasename; string datasourceviewname; string datasourcename; string tableName; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string connstring = "Data Source=localhost;Integrated Security=True"; SqlConnection connection = new SqlConnection(connstring); string query = "select * from sys.databases"; SqlDataAdapter data = new SqlDataAdapter(query, connection); DataTable dtable = new DataTable(); try { connection.Open(); int records = data.Fill(dtable); if (records > 0) { foreach (DataRow dr in dtable.Rows) { //Console.WriteLine(dr[0]); comboBox1.Items.Add(dr[0]); } } } catch (SqlException sqlexcp) { MessageBox.Show("connection error"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { dbname = comboBox1.Text; } private void button1_Click(object sender, EventArgs e) { /*databasename = dbname; datasourceviewname = "oor"; connectionstring = "Data Source=localhost;Integrated Security=True"; //create a datasource name RelationalDataSource newDS = new RelationalDataSource(datasourceviewname, Utils.GetSyntacticallyValidID(datasourceviewname, typeof(RelationalDataSource))); Database db = new Database("oor"); db.DataSources.Add(newDS); newDS.ConnectionString = connectionstring; newDS.Update();*/ Server server = new Server(); databasename = "cwh_temp"; s

    T 1 Reply Last reply
    0
    • B bobolov

      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; using Microsoft.AnalysisServices; using Microsoft.DataWarehouse.Interfaces; using System.Data.OleDb; using System.Data.Common; namespace DatabaseApplication { public partial class Form1 : Form { string dbname; string connectionstring; string databasename; string datasourceviewname; string datasourcename; string tableName; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string connstring = "Data Source=localhost;Integrated Security=True"; SqlConnection connection = new SqlConnection(connstring); string query = "select * from sys.databases"; SqlDataAdapter data = new SqlDataAdapter(query, connection); DataTable dtable = new DataTable(); try { connection.Open(); int records = data.Fill(dtable); if (records > 0) { foreach (DataRow dr in dtable.Rows) { //Console.WriteLine(dr[0]); comboBox1.Items.Add(dr[0]); } } } catch (SqlException sqlexcp) { MessageBox.Show("connection error"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { dbname = comboBox1.Text; } private void button1_Click(object sender, EventArgs e) { /*databasename = dbname; datasourceviewname = "oor"; connectionstring = "Data Source=localhost;Integrated Security=True"; //create a datasource name RelationalDataSource newDS = new RelationalDataSource(datasourceviewname, Utils.GetSyntacticallyValidID(datasourceviewname, typeof(RelationalDataSource))); Database db = new Database("oor"); db.DataSources.Add(newDS); newDS.ConnectionString = connectionstring; newDS.Update();*/ Server server = new Server(); databasename = "cwh_temp"; s

      T Offline
      T Offline
      tom572007
      wrote on last edited by
      #2

      Where do you get an error? wich line?

      B 1 Reply Last reply
      0
      • T tom572007

        Where do you get an error? wich line?

        B Offline
        B Offline
        bobolov
        wrote on last edited by
        #3

        line number : 140

        D L 2 Replies Last reply
        0
        • B bobolov

          line number : 140

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          and that line would be.....???? Notice, in your original post, you didn't supply any lines numbers!

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          B 1 Reply Last reply
          0
          • B bobolov

            line number : 140

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            then use your IDE's editor to investigate line 140 (you have turned on "display line numbers" I trust). whatever object reference gets dereferenced (as in myObject.something) is a candidate for being null and generating said exception. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


            1 Reply Last reply
            0
            • D Dave Kreskowiak

              and that line would be.....???? Notice, in your original post, you didn't supply any lines numbers!

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              B Offline
              B Offline
              bobolov
              wrote on last edited by
              #6

              i've highligthed and underlined the line that was giving me a nullreference exception.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups