inserting an image to sql server

livnia

New member
inserting an image to sql server

[email protected] in msn messenger hi i try to insert an image to sqlserver i do like this first i wrote a stored procedure in my sql server in database="new_home" (not in master db) : CREATE PROCEDURE sp_textcopy ( @srvname varchar (30), @login varchar (30), @password varchar (30), @dbname varchar (30), @tbname varchar (30), @colname varchar (30), @filename varchar (30), @whereclause varchar (40), @direction char(1)) AS DECLARE @exec_str varchar (255) SELECT @exec_str = 'textcopy /S ' + @srvname + ' /U ' + @login + ' /P ' + @password + ' /D ' + @dbname + ' /T ' + @tbname + ' /C ' + @colname + ' /W "' + @whereclause + '" /F ' + @filename + ' /' + @direction EXEC master..xp_cmdshell @exec_str this stored procedure i add to : db="new_home" table="image" now i only try to give parmeters in asp.net in oledb , i saw the example : sp_textcopy@srvname = 'ServerName', @login = 'Login', @password = 'Password', @dbname = 'pubs', @tbname = 'pub_info', @colname = 'logo', @filename = 'c:\picture.bmp', @whereclause = " WHERE pub_id='0736' ", @direction = 'I' but i do not now where i write this code and how i write it asp.net instead i write this, but i didnot see any new image in my database : <%@ Import Namespace="System.Data.SQLClient" %> <%@ Import Namespace="System.Data.OLEDB" %> <%@ Page Language="VB" Debug="true" %> <script language="VB" runat="server"> sub Page_Load(obj as Object, e as EventArgs) 'set up connection dim Conn as new OleDbConnection _ ("Provider=SQLOLEDB;" & _ "Data Source=D:\Program Files\Microsoft SQL Server\MSSQL$LOVE\Data\new_home_Data.MDF") dim obdCmd as OleDbCommand = new OleDbCommand("sp_textcopy",Conn) obdCmd.CommandType = CommandType.StoredProcedure dim objParam as OleDbParameter (a comment my in sql server group my servername is AAA\LOVE-AAA is the domain and LOVE is the instance i have no username or password to sql server i have only windows authentication which include username and password when windows is started i want to insert the image to the db: "new_home" to table:"image" to column:"image" which is image type ) objParam =obdCmd.Parameters.Add("@srvname", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="AAA\LOVE" objParam =obdCmd.Parameters.Add("@login", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="" objParam =obdCmd.Parameters.Add("@password", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="" objParam =obdCmd.Parameters.Add("@login", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="" objParam =obdCmd.Parameters.Add("@dbname", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="new_home" objParam =obdCmd.Parameters.Add("@ltbname", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="image" objParam =obdCmd.Parameters.Add("@colname", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="image" objParam =obdCmd.Parameters.Add("@filename", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="c\10.jpg" objParam =obdCmd.Parameters.Add("@whereclause", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="where id=1" objParam =obdCmd.Parameters.Add("@direction", OleDbType.Char) objParam.Direction=ParameterDirection.Input objParam.Value="i" try obdCmd.Connection.Open() dim objReader as OleDbDataReader objReader = obdCmd.ExecuteReader catch ex as OleDbException response.write("Error retriving Data") obdCmd.Connection.Close() end try end sub </script>
 
למעלה