NullReferenceException object reference not set to an instance of an object..please help
-
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
-
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
-
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 -
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
-
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