Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从c语言的数据库中获取信息(没有SqlConnection类)_C#_Database_Forms_Winforms_Sqlconnection - Fatal编程技术网

C# 如何从c语言的数据库中获取信息(没有SqlConnection类)

C# 如何从c语言的数据库中获取信息(没有SqlConnection类),c#,database,forms,winforms,sqlconnection,C#,Database,Forms,Winforms,Sqlconnection,你好,Stackoverflow社区,我是C和数据库的新手,我有以下问题: 我正在编写一个windows窗体应用程序,其中一个窗体是登录屏幕,用户可以在其中的文本字段中键入自己的姓名。我想检查我的数据库中是否已经存在该名称,并且不知道如何将textfield信息移交给数据库 我看过一些教程,但它们都是使用SqlConnectionClass的。 我通过Visual Studio曲面视图>其他窗口>数据源将项目与数据库连接 您能告诉我如何解决这个问题吗?我不知道您的窗体设计,但我希望以下代码能有所

你好,Stackoverflow社区,我是C和数据库的新手,我有以下问题:

我正在编写一个windows窗体应用程序,其中一个窗体是登录屏幕,用户可以在其中的文本字段中键入自己的姓名。我想检查我的数据库中是否已经存在该名称,并且不知道如何将textfield信息移交给数据库

我看过一些教程,但它们都是使用SqlConnectionClass的。 我通过Visual Studio曲面视图>其他窗口>数据源将项目与数据库连接


您能告诉我如何解决这个问题吗?

我不知道您的窗体设计,但我希望以下代码能有所帮助:

SqlConnection conn = new SqlConnection(@"here goes your connection string"); // select your data source goto properties and you may see your connection string over there
        SqlDataAdapter sda = new SqlDataAdapter("select count(*) from your_table_name where username ='" + textBox1.Text + "' and password='" + textBox2.Text + "'", conn);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        if (dt.Rows[0][0].ToString() == "1")
        {
            this.Hide();
            Form2 f = new Form2();
            f.Show();
        }
        else
        {
            MessageBox.Show("please enter correct username and password", "alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

大家好,欢迎来到Stack Overflow。你应该找到一个关于如何使用数据库的教程,我能给出的最好答案是,你需要编写涉及使用SqlConnection或其他使用它的东西的代码,但问题太广泛和模糊了,就目前而言,我写的任何东西都可能引发新的问题。你能把这篇文章看一看,看它是否适合你吗。