This question is somewhat similar and related to my previous question How to get data in an sql foreign key using asp.net entity framework? so I will be using the same SQL Server tables.
This time, instead of accessing the foreign key value through Entity Framework, I want to know how to do it in a regular SQL script like this (take note, the script that I'm talking about is inside the string.Format):
public static void getRowNumber(string brand)
{
string query = string.Format("SELECT COUNT(*) FROM stringInstrumentItem WHERE brandId LIKE @brand");
conn1.Open();
command1.CommandText = query;
command1.Parameters.Add(new SqlParameter("brand", brand));
Int32 count = (Int32)command1.ExecuteScalar();
conn1.Close();
command1.Parameters.Clear();
AddASPXAndCSFile.X = count;
}
Just to recap, I have two SQL Server tables called stringInstrumentItem and brand. I created the foreign key in the table stringInstrumentItem referring to the primary key of the table brand. So I'm attempting to access the column name in table brand through stringInstrumentItem.
As you can see, I'm attempting to access the value in table brand through brandId, which does not work.
Hope you guys can help me on this one. Cheers!
brandId? Usually anIDcolumn is int.@sign in thisnew SqlParameter("@brand", brand)to access the parameter.