473,466 Members | 1,296 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing Parameter value in vb.net

Hi,
I am trying to pass parameter value to ODBCCommand object.
but it is not assigning values , the null value is gets stored. i m using following code,

Private Sub cmdsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Dim command As New OdbcCommand
Dim str As String

Dim photo() As Byte = GetPhoto(txtpath.Text)
str= insert into emp(id, name, photo) values (1,@name,@photo)
command = New OdbcCommand(str, con.cn) ' con.cn is connection object
command.Parameters.Add("@name", OdbcType.VarChar, 20).Value = "sagar"
command.Parameters.Add("@photo", OdbcType.Image, photo.Length).Value = photo
command.ExecuteNonQuery()
msgbox "saved"
End Sub

Public Shared Function GetPhoto(ByVal filePath As String) As Byte()
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim photo As Byte() = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return photo
End Function

Please can anyone help me?

Regards
Programmer2004

Nov 20 '05 #1
3 2625
Hi Programmer,

I would not use ODBC in dotNet anymore, use when you are able to SQLclient
and when not OleDB.

ODBC gives mostly a lot of troubles and after a while the one who tried goes
to OleDb.

And have a look at the dataset, however the links I gave you in your message
above will probably help you. (Take a look at the dataset).

Cor
Nov 20 '05 #2
* "=?Utf-8?B?cHJvZ3JhbW1lcjIwMDQ=?=" <pr************@discussions.microsoft.com> scripsit:
I am trying to pass parameter value to ODBCCommand object.


In addition to the other replies: There is a separate group for .NET +
database related questions available:

<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
programmer2004,
In addition to the ADO.NET newsgroup that Herfried identified, you may try
the microsoft.public.dotnet.framework.odbcnet newsgroup as it deals
specifically with ODBC in ADO.NET issues...

URL:news://news.microsoft.com/microsoft....mework.odbcnet

Web interface:

URL:http://msdn.microsoft.com/newsgroups...mework.odbcnet

Hope this helps
Jay

"programmer2004" <pr************@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
Hi,
I am trying to pass parameter value to ODBCCommand object.
but it is not assigning values , the null value is gets stored. i m using following code,
Private Sub cmdsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdsave.Click Dim command As New OdbcCommand
Dim str As String

Dim photo() As Byte = GetPhoto(txtpath.Text)
str= insert into emp(id, name, photo) values (1,@name,@photo)
command = New OdbcCommand(str, con.cn) ' con.cn is connection object command.Parameters.Add("@name", OdbcType.VarChar, 20).Value = "sagar"
command.Parameters.Add("@photo", OdbcType.Image, photo.Length).Value = photo command.ExecuteNonQuery()
msgbox "saved"
End Sub

Public Shared Function GetPhoto(ByVal filePath As String) As Byte()
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read) Dim br As BinaryReader = New BinaryReader(fs)
Dim photo As Byte() = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return photo
End Function

Please can anyone help me?

Regards
Programmer2004

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
6
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
0
by: Phillip Vong | last post by:
Doing this in VS2005. ASPX in VB code. This image details my problem. http://ebay.philvong.com/help.jpg I have a simple FormView1 bound to a SQLDataSource1. In edit mode, Label1 is bound to a...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.