0

I am just wondering how can I check if a database exists in C# using ADO.net without EF. please advise .thanks so much

Below is my Controller

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(string Name, string ID)
{
      string myConnectionString;
      DataTable dt = new DataTable();
      //connect DB
      myConnectionString = "Data Source=xxxxxx"
      //Validation   
    if (ModelState.IsValid)
    {
        using (SqlConnection sqlConn = new
        SqlConnection(myConnectionString))
        {
            string sql = "insert into [DB] (ID,Name) Values('" + ID + "','" + Name + ")";
            using (SqlCommand sqlCmd = new SqlCommand(sql, sqlConn))
            {
                sqlCmd.CommandType = CommandType.Text;
                sqlConn.Open();
                using (SqlDataAdapter sqlAdapter = new
                    SqlDataAdapter(sqlCmd))
                {
                    sqlAdapter.Fill(dt);
                }
            }
        }
    }
}
3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.