Bip
Bip

Reputation: 697

The multi-part identifier "xxx" could not be bound

sqlComm.Connection = sqlConn;

sqlComm.Parameters.AddWithValue("@Kullanici", Kullanici);
sqlComm.Parameters.AddWithValue("@Sifre", Sifre);
sqlComm.Parameters.AddWithValue("@Ad", Ad);
sqlComm.Parameters.AddWithValue("@Soyad", Soyad);
sqlComm.Parameters.AddWithValue("@Parametre", rndParametre);

sqlComm.CommandText = "INSERT INTO Kullanici (EPosta,Sifre,Ad, Soyad,Aktif,Parametre, __DZamani) " +
                      " VALUES (@Kullanici,@Sifre,@Ad,@Soyad, 0,@Parametre,getdate()); SELECT RecID FROM Kullanici WHERE EPosta= "+ Kullanici;


sqlConn.Open();              
SqlDataReader sqlRead = sqlComm.ExecuteReader();
while (sqlRead.Read())
{
    RecID = Convert.ToInt32(sqlRead["RecID"]);
}               
sqlConn.Close();

I have error: The multi-part identifier "[email protected]" could not be bound how to fix this error? do you have any idea?

Upvotes: 1

Views: 3033

Answers (1)

Oded
Oded

Reputation: 498904

This is where the issue is:

SELECT RecID FROM Kullanici WHERE EPosta= "+ Kullanici;

You are not quoting the VARCHAR/NVARCHAR field, so SQL thinks this is a table name, which it can't find.

You should be using the same parameter as you do elsewhere - it is not clear why here, and only here you are concatenating SQL. This opens you up to SQL Injection, so you should be using the parameter you already have:

SELECT RecID FROM Kullanici WHERE EPosta= @Kullanici";

Upvotes: 6

Related Questions