Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

How to resolve the error of SQL invalid object name?

Asked by Camellia Kleiber Mar 15, 2023 1.3K views 1 answer
Share

About this question

I connect the database with Visual Studio 2017. When I am trying to execute a query then it shows the following error:

The connection string I am using is:

SqlConnection con = new SqlConnection("Data Source=ANUPAM-DESKTOPANUPAM;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"); 

My code:

public void exicuteDatabaseQuery(String query)
    {
        con.Open();
        SqlDataAdapter sda = new SqlDataAdapter(query, con);
        sda.SelectCommand.ExecuteNonQuery();
        con.Close();
        MessageBox.Show("Successfull");
    }
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        int id = Convert.ToInt32(___Id_.Text);
        int number = Convert.ToInt32(___Number_.Text);
        String InsertQuery = "INSERT INTO Member (id, number) 
        values('"+id+"','"+number+"')";
        exicuteDatabaseQuery(InsertQuery);
    }

Database explorer image:

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.