簡體   English   中英

從C#Windows Form應用程序連接到sql時出錯

[英]error in connecting to sql from C# windows form application

我在C#中有一個獲取用戶和通過的表單,並且有一個顯示雇員信息的表單,還有兩個表都在sql server中,我想在Gridview中顯示。

private void button1_Click(object sender, EventArgs e)
{
    String UserId = textBox1.Text;
    String passwrd = textBox2.Text;
    SqlConnection myConnection = new SqlConnection("Server=.,SQL2014;Database=MyTamrin;uid=Sa;password=Sa123;");
    try
    {
        myConnection.Open();
    }
    catch (Exception r)
    {
        MessageBox.Show(r.ToString());
        Console.WriteLine(r.ToString());
    }

    SqlCommand sqlcomm = new SqlCommand();

        sqlcomm.CommandText = "SELECT count(*) FROM dbo.Empp WHERE fldUserName = @snum AND fldPassword = @pass";
        sqlcomm.Parameters.AddWithValue("@snum", UserId);
        sqlcomm.Parameters.AddWithValue("@pass", passwrd);
        if ((Int16)sqlcomm.ExecuteScalar()==1)
        {
            Userinfo mainform = new Userinfo();
            mainform.Show();

        } 

問題是什么?

您未指定以下內容:

sqlComm.Connection = myConnection;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM