Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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#.net检查登录详细信息_C#_Mysql_Sql Server_Syntax Error_Adapter - Fatal编程技术网

使用c#.net检查登录详细信息

使用c#.net检查登录详细信息,c#,mysql,sql-server,syntax-error,adapter,C#,Mysql,Sql Server,Syntax Error,Adapter,我得到一个错误: 无法将MySql.Data.MysqlClient.MySqlCommand转换为 SqlDataAdapter sda处的“System.Data.SqlClient.SqlCommand”为新的SqlDataAdapter(cmd) 我认为您应该使用System.Data.OleDb名称空间,并且在该名称空间中有相同的类。表示您应该使用OleDbConnection而不是SqlConnection,并且可以使用OleDbDataAdapter代替SqlDataAdapter

我得到一个错误:


无法将MySql.Data.MysqlClient.MySqlCommand转换为 SqlDataAdapter sda处的“System.Data.SqlClient.SqlCommand”为新的SqlDataAdapter(cmd)


我认为您应该使用
System.Data.OleDb名称空间,并且在该名称空间中有相同的类。表示您应该使用
OleDbConnection
而不是
SqlConnection
,并且可以使用
OleDbDataAdapter
代替
SqlDataAdapter


我认为应该行得通。希望这会有所帮助。

您正在尝试使SqlDataAdapter(用于MS SQL的)与MySqlCommand一起工作。有一个,所以看起来你需要用它来代替。 但无论如何,这段代码毫无意义:

SqlDataAdapter sda = new SqlDataAdapter(cmd);// getting error here 
DataTable dt = new DataTable();
sda.Fill(dt);

int i = cmd.ExecuteNonQuery();
您正在调用DataAdapter以通过SqlCommand填充DataTable,然后使用ExecuteOnQuery再次调用该SqlCommand。那完全是胡说八道。 您需要将代码更改为(可能):


请注意使用
而不是直接
连接的
。Close()
我认为您应该更改

 SqlDataAdapter sda = new SqlDataAdapter(cmd);


因为SqlDataAdapter不会被MySqlCommand重载。

无法在SqlDataAdapter sda=new SqlDataAdapter(cmd)处从MySql.Data.MysqlClient.MySqlCommand转换为“System.Data.SqlClient.SqlCommand”;尝试设置sda.selectcommand=cmd;您可能应该使用
MySqlDataAdapter
,因为
SqlDataAdapter
用于SQL server,而不是MySQL。SqlDataAdapter需要SqlCommand,所以创建该对象而不是MySqlCommand@adil…但仅当您连接的是Microsoft SQL Server而不是MySQL服务器时
string MyConnectionString = "Server=localhost;Database=smsjobs;Uid=root;pwd=root;";

protected void Submit_Click(object sender, EventArgs e) { 
    using(var connection = new MySqlConnection(MyConnectionString)) {
        connection.Open(); 
        var cmd = connection.CreateCommand();

        cmd.CommandText="select * from userdetails where db_mobi=@username and db_pass=@word";
        cmd.Parameters.AddWithValue("@username", cn_mobi.Text);
        cmd.Parameters.AddWithValue("@word", cn_pass.Text);

        var reader = cmd.ExecuteReader();
        if (reader.HasRows)
        {
            Session["id"] = cn_mobi.Text;
            Response.Redirect("Redirectform.aspx");
            Session.RemoveAll();
        }
    }
}
 SqlDataAdapter sda = new SqlDataAdapter(cmd);
 MySqlDataAdapter sda = new MySqlDataAdapter (cmd);