Invalid object name

  • Thread starter Thread starter Reb
  • Start date Start date
R

Reb

Hi,

I am using MSSQL server 2000. When i am running my code, i
am getting the error System.Data.SqlClient.SqlException:
Invalid object name 'Item'
where Item is the name of a table.
It seems like the code couldn't identify the table. any
idea of what could be wrong?

thanks
 
Hi,

I am actually getting to know about the code written by
another person.

There are many files involved with this.

He has used typed dataset and has written all the sql
statements in the InitializeComponent() in the start page.
 
Sorry about

foreach(DataRow row in dsClientes.Tables["Cli_Clientes"].Rows)
{
MessageBox.Show(row["fieldname"].ToString())
}

This must be:

foreach(DataRow row in dsClientes.Tables["Item"].Rows)
{
MessageBox.Show(row["fieldname"].ToString())
}

Cut and Paste. ;-)
Juan Galdeano said:
I make this 2 methods that return a SQLConnection, the first one is for SQL
Server Security Scheme and the second is for Integrated Security Scheme.

public static SqlConnection ConnectToSQL(string server, string database,
string user, string password)
{
string connectionstring = "server=" + server.Trim() + ";";
connectionstring += "uid=" + user + ";";
connectionstring += "pwd=" + password + ";";
connectionstring += "database=" + database.Trim() + ";";
SqlConnection connection = new SqlConnection(connectionstring);
connection.Open();
return connection;
}

public static SqlConnection ConnectToSQL(string server, string database)
{
SqlConnection nwindConn = new SqlConnection();
string connectionstring = "Data Source=" + server.Trim() + ";Integrated
Security=SSPI;Initial Catalog=" + database.Trim() + ";";
SqlConnection connection = new SqlConnection(connectionstring);
connection.Open();
return connection;
}

If this works fine then create the DataSet.

DataSet ds = new DataSet("Test");
string sql = "SELECT * FROM Item";
(new SqlDataAdapter(sql, connection)).Fill(ds, "Item");

After that, the DataSet ds should have the table and records. If you want
read the records, you could use:

foreach(DataRow row in dsClientes.Tables["Cli_Clientes"].Rows)
{
MessageBox.Show(row["fieldname"].ToString())
}

Hope this help you.

Reb said:
Hi,

I am actually getting to know about the code written by
another person.

There are many files involved with this.

He has used typed dataset and has written all the sql
statements in the InitializeComponent() in the start page.
 
Back
Top