我试图在SQL Server数据库中包含我创建的类的对象。我正在尝试将其转换为VARBINARY
,但方法Add
无法识别VARBINARY
类型。我得到的错误是:
VARBINARY:未声明的标识符。
我正在使用名称空间System.Data
和System.Data.SqlClient
。
这是我的代码:
MemoryStream^ memStream = gcnew MemoryStream();
StreamWriter^ sw = gcnew StreamWriter(memStream);
sw-> Write (eyemax);
SqlConnection^ myConnection = gcnew SqlConnection();
myConnection->ConnectionString = "Data Source = (localdb)\\ProjectsV13;AttachDbFilename\=C:\\Users\\Usuario\\AppData\\Local\\Microsoft\\VisualStudio\\SSDT\\TUKDatabase.mdf; Integrated Security = True; Connect Timeout = 30";
myConnection->Open();
SqlCommand^ cmd = gcnew SqlCommand("INSERT INTO Features(Face,Eye) VALUES (@face, @eye)",myConnection);
cmd->Parameters->AddWithValue("@face", face);
cmd->Parameters->Add("@eye",SqlDbType(VarBinary));
cmd->Parameters["@eye"]->Value = memStream->GetBuffer();