locked
VB Language RRS feed

  • Question

  • User888242859 posted

     Can someone translate the following to VB language please?

    Thanks.

     ---------------------------------------------

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Data.SqlClient;

    using System.Data.Sql;

    using System.IO;

    public partial class ImageUpload : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void btnUpload_Click(object sender, EventArgs e)

    {

    Stream imgStream = fuImage.PostedFile.InputStream;

    int imgLen = fuImage.PostedFile.ContentLength;

    string imgName = txtImageName.Text;

    string imgJob = TxtImageJob.Text;

    string imgAddress = TxtImageAddress.Text;

    byte[] imgBinaryData = new byte[imgLen];

    int n = imgStream.Read(imgBinaryData,0,imgLen);

    //use the web.config to store the connection string

    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString1"].ConnectionString);

    SqlCommand command = new SqlCommand("INSERT INTO Image (imagename,image,Job,Address) VALUES ( @img_name, @img_data, @img_job, @img_address)", connection);

    SqlParameter param0 = new SqlParameter("@img_name", SqlDbType.NVarChar, 20);

    param0.Value = imgName;

    command.Parameters.Add(param0);

    SqlParameter param1 = new SqlParameter("@img_data", SqlDbType.Image);

    param1.Value = imgBinaryData;

    command.Parameters.Add(param1);

     

    SqlParameter param2 = new SqlParameter("@img_job", SqlDbType.NVarChar, 20);

    param2.Value = imgJob;

    command.Parameters.Add(param2);

    SqlParameter param3 = new SqlParameter("@img_address", SqlDbType.NVarChar, 20 );

    param3.Value = imgAddress;

    command.Parameters.Add(param3);

    connection.Open();

    int numRowsAffected = command.ExecuteNonQuery();

    connection.Close();

    }

    }

    Monday, September 22, 2008 6:33 PM

All replies

  • User-340921419 posted

    Imports System

    Imports System.Data

    Imports System.Configuration

    Imports System.Collections

    Imports System.Web

    Imports System.Web.Security

    Imports System.Web.UI

    Imports System.Web.UI.WebControls

    Imports System.Web.UI.WebControls.WebParts

    Imports System.Web.UI.HtmlControls

    Imports System.Data.SqlClient

    Imports System.Data.Sql

    Imports System.IO

    Public Partial Class ImageUpload
        Inherits System.Web.UI.Page
       
       
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
           
        End Sub
       
        Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
           
            Dim imgStream As Stream = fuImage.PostedFile.InputStream
            Dim imgLen As Integer = fuImage.PostedFile.ContentLength
           
            Dim imgName As String = txtImageName.Text
            Dim imgJob As String = TxtImageJob.Text
           
            Dim imgAddress As String = TxtImageAddress.Text
            Dim imgBinaryData As Byte() = New Byte(imgLen - 1) {}
           
            Dim n As Integer = imgStream.Read(imgBinaryData, 0, imgLen)
            'use the web.config to store the connection string
           
            Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("TestConnectionString1").ConnectionString)
            Dim command As New SqlCommand("INSERT INTO Image (imagename,image,Job,Address) VALUES ( @img_name, @img_data, @img_job, @img_address)", connection)
           
            Dim param0 As New SqlParameter("@img_name", SqlDbType.NVarChar, 20)
            param0.Value = imgName
           
            command.Parameters.Add(param0)
           
            Dim param1 As New SqlParameter("@img_data", SqlDbType.Image)
            param1.Value = imgBinaryData
           
            command.Parameters.Add(param1)
           
           
           
            Dim param2 As New SqlParameter("@img_job", SqlDbType.NVarChar, 20)
            param2.Value = imgJob
           
            command.Parameters.Add(param2)
           
            Dim param3 As New SqlParameter("@img_address", SqlDbType.NVarChar, 20)
            param3.Value = imgAddress
           
            command.Parameters.Add(param3)
           
            connection.Open()
           
            Dim numRowsAffected As Integer = command.ExecuteNonQuery()
            connection.Close()
           
        End Sub
       
    End Class

    Monday, September 22, 2008 6:43 PM
  • User888242859 posted

    Thanks for your help.

    My application is not working yet. I needed in VB for school. When debugging I get the following error

    <a href="javascript:void(window.open('<%# "FullImage.ashx?ImID="+ Eval("ImageID")%>','_blank','toolbar=no,menubar=no'))" >

    System.FormatException: Input string was not in a correct format.

     

    Monday, September 22, 2008 10:42 PM
  • User201647903 posted

    First - try this website to convert C# to VB: http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

    Second, try this to open a new window with VB/JavaScript:  

    <script type="text/javascript">
     function openyourwindow()
          {
            javascript:window.open("http://yourwindownamehere.aspx");
          }  
    </script>

    Third - it looks like you are trying to open a window maximized?  I'm not quite sure exactly what you are tying to do with your window.open script, but check out this web site, maybe it will give you some information to do what you are trying to do... http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

    And don't forget to mark it as the answer if it helps you - thanks!

    Tuesday, September 23, 2008 10:11 AM