【问题标题】:how to insert image using command.Parameters如何使用 command.Parameters 插入图像
【发布时间】:2014-06-22 11:48:30
【问题描述】:

当我将图像插入数据库时​​,它是空白的。

这是我的代码:

            string sql = "INSERT INTO tblProfile(EmployeeID,FirstName, MiddleName,LastName,Gender,Age,Email, DateofBirth,RFID,PlaceofBirth,MaritalStatus,SSS,TIN,PhilHealth, Mobile,City, HomeAddress, Nationality, Religion,ContactPerson,ContactNumber,Image)" +
                "VALUES(@ID,@FirstName,@MiddleName,@LastName,@Gender,@Age,@Email,@DateofBirth,@RFID,@PlaceofBirth,@MaritalStatus,@SSS,@TIN,@PhilHealth, @Mobile,@City,@HomeAddress, @Nationality, @Religion,@ContactPerson,@ContactNumber,@IMG)";
            if (conn.State != ConnectionState.Open)
                conn.Open();
            command = new SqlCommand(sql, conn);

            command.Parameters.Add("@ContactNumber", SqlDbType.VarChar).Value = Convert.ToString(txtContactNumber_New.Text);                                               
            command.Parameters.Add(new SqlParameter("@IMG", img));

【问题讨论】:

标签: c#-4.0


【解决方案1】:

如果您没有从评论中的链接获得,则必须执行以下操作。

byte[] img = // Read you image as byte array.
var _SqlParameter  = new SqlParameter("@Img", SqlDbType.Image);
_SqlParameter.Value = img;
// In above line img should be by array.

您可以在此处找到更完整的示例。 http://msdn.microsoft.com/en-us/library/4f5s1we0(v=vs.110).aspx

【讨论】:

    猜你喜欢
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 2023-03-30
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多