|
This might help
http://support.microsoft.com/kb/315577
|
|
|
|
|
First the setup
My Code:
<br />
Imports System.Data.SqlClient<br />
Imports System.Text<br />
Public Class Form1<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
Dim myConnection As New SqlConnection()<br />
Dim myDataSet As New DataSet()<br />
Dim myDataAdapter As SqlDataAdapter<br />
Dim myUpdateCommand As SqlCommand<br />
Dim myNewStr As String<br />
<br />
'create connection string<br />
myConnection.ConnectionString ="Server=.;Database=TestDB;UID=steve;pwd=password;Trusted_Connection=yes;"<br />
<br />
'open connection to DB<br />
myConnection.Open()<br />
<br />
'setup data adapter <br />
myDataAdapter = New SqlDataAdapter("select TEXT from SCRIPTS WHERE ID=1", myConnection)<br />
<br />
'Initialize the SqlCommand object that will be used as the DataAdapter's UpdateCommand.<br />
'Note that the WHERE clause uses only the CustId field to locate the record that is to be updated.<br />
myUpdateCommand = New SqlCommand("UPDATE SCRIPTS SET TEXT=@pNewText FROM SCRIPTS WHERE ID =@pMyID", myDataAdapter.SelectCommand.Connection)<br />
<br />
'Create and append the parameters for the Update command.<br />
myUpdateCommand.Parameters.Add(New SqlParameter("@pNewText", SqlDbType.VarChar))<br />
myUpdateCommand.Parameters("@pNewText").SourceVersion = DataRowVersion.Current<br />
myUpdateCommand.Parameters("@pNewText").SourceColumn = "TEXT"<br />
<br />
myUpdateCommand.Parameters.Add(New SqlParameter("@pMyID", SqlDbType.Int))<br />
myUpdateCommand.Parameters("@pMyID").SourceVersion = DataRowVersion.Original<br />
myUpdateCommand.Parameters("@pMyID").SourceColumn = "ID"<br />
<br />
<br />
'Assign the SqlCommand to the UpdateCommand property of the SqlDataAdapter.<br />
myDataAdapter.UpdateCommand = myUpdateCommand<br />
<br />
'call the fill method to populate our dataset<br />
myDataAdapter.Fill(myDataSet, "SCRIPTS")<br />
<br />
'present the current entry in database<br />
MsgBox("Script before updating" + vbCrLf + Encoding.Unicode.GetString(myDataSet.Tables("SCRIPTS").Rows(0)("TEXT")))<br />
<br />
'modify current with replace to update field<br />
myNewStr = Replace(Encoding.Unicode.GetString(myDataSet.Tables("SCRIPTS").Rows(0)("TEXT")), "hello", "steve")<br />
<br />
'now convert our replaced field to a byte array<br />
Dim dBytes As Byte()<br />
dBytes = StrToByteArray(myNewStr)<br />
<br />
'set the dataset table row to our converted byte array<br />
myDataSet.Tables("SCRIPTS").Rows(0)("TEXT") = dBytes<br />
<br />
'call the update method to write back to DB<br />
myDataAdapter.Update(myDataSet, "SCRIPTS")<br />
<br />
'close connection<br />
myConnection.Close()<br />
<br />
End Sub<br />
<br />
Public Shared Function StrToByteArray(ByVal str As String) As Byte()<br />
<br />
'converts string to byte array<br />
Dim encoding As New System.Text.ASCIIEncoding()<br />
Return encoding.GetBytes(str)<br />
<br />
End Function<br />
<br />
End Class<br />
DB SETUP
-----------
Column Name Data Type
ID int (primary key)
TEXT image
DB Records:
ID=1
TEXT =
1040101010801080111033013010010301110111010009801210101033013010083011609701140116033013010010201050110011501050104033013010010401010108010801110330
(
when converted to string is:
hello!
goodbye!
Start!
finsih!
hello!
)
My code works perfect up until the point of the update method
myDataAdapter.Update(myDataSet, "TP_SCRIPTS")
Once I hit this line, i get an error saying :Failed to convert parameter value from a Byte[] to a String.
Help please!
-steve
|
|
|
|
|
svanwass wrote: 'Create and append the parameters for the Update command.
myUpdateCommand.Parameters.Add(New SqlParameter("@pNewText", SqlDbType.VarChar))
You created this parameter as a string, not as a binary type. This is where the error is comming from.
|
|
|
|
|
I am working on a project trying to get my DB and VB.NET skills up to speed. I have established a connection to my database and linked a combobox to the database thusly:
ComboBox1.DataSource = techDataSet.Tables("tblEmployee")
ComboBox1.DisplayMember = "EmployeeName"
However this puts the first record into the "textbox" portion of the ComboBox. I would prefer the ComboBox "textbox" portion to be empty and all the database information be in the dropdown...
Any help would be appreciated.
My goal in life is to be the kind of person my dog thinks I am.
|
|
|
|
|
All you need to do is set the SelectedIndex of the ComboBox = -1. That will take care of it.
|
|
|
|
|
Excellent,thanks.
My goal in life is to be the kind of person my dog thinks I am.
|
|
|
|
|
Hi!
I have this code:
<br />
Dim mailMsg As New MailMessage("webmaster1@myhost.com", "webmaster2@xxxxxxxxx.com", "Test", "Test and Spam")<br />
Dim mysmtp As SmtpClient<br />
mysmtp = New SmtpClient("mail.myhost.com")<br />
<br />
Try<br />
mysmtp.Send(mailMsg)<br />
MessageBox.Show("Sended!", _<br />
"Email Send Status", MessageBoxButtons.OK, _<br />
MessageBoxIcon.Information)<br />
Catch exp As Exception<br />
MessageBox.Show("Error:" & exp.Message, _<br />
Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)<br />
End Try<br />
In Microsoft Visual Studio 2005, VB.NET
How I can use also a username and the passwoed?
Thanks!
My site: www.logicpc.co.il
|
|
|
|
|
I have added one line to your code for username and password
'Your Code
Dim mailMsg As New MailMessage("webmaster1@myhost.com", "webmaster2@xxxxxxxxx.com", "Test", "Test and Spam")
Dim mysmtp As SmtpClient
mysmtp = New SmtpClient("mail.myhost.com")
Try
'Add this code
mysmtp.Credentials = New System.Net.NetworkCredential(username, password)
'
mysmtp.Send(mailMsg)
MessageBox.Show("Sended!", _
"Email Send Status", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch exp As Exception
MessageBox.Show("Error:" & exp.Message, _
Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
|
|
|
|
|
Thanks for you! Worked.
My site: www.logicpc.co.il
|
|
|
|
|
i have a table that has no Triggers and all the Fields in my table are nullable and have an Identity Column that is no giving me problem.
am inserting data from my vb.net frontend to my table. sometimes users dont have anything to input, so i want to allow my Adapter to input Null in the dataset when the user has not inserted in data in the text. i used the dragg and drop technique(draging table into the form) here is my SQl statement
<br />
SELECT NUM_KEY, EXTENSION, CELL_ID, ACTUAL_EXTENT, PROP_CATEGORY_ID, LIS_KEY, FUNC_KEY, RATEABLE, GEOCODE, NON_DISCREET_VALID, PROPERTY_ID FROM PROPERTY<br />
i want all this fields to accepts null values in the dataset, because i know that when i run the update function, my table wont complain because all this fields accepts Null values.
Thanks
Vuyiswa
|
|
|
|
|
You should validate your form and avoid null in the DB where-ever possible.
Why do you want null and not an empty string ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Am Sorry to put it that way, i meant Empty string, but the thing sometimes the user might enter something, what if the user does not enter anything?
Vuyiswa
|
|
|
|
|
Then the user has actually entered an empty string. An empty string is entered into the database exactly the same as a string of length greater than 0.
An empty string is most certainly not null.
|
|
|
|
|
Thanks Dave,
i have solved the Problem , by converting everting input from a user to string, if the user enters nothing then, it wil be converted to empty String , and in my table it will be null.i have put this code in the Textchanged event
<br />
<br />
me.Tostring<br />
<br />
Thanks
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: me.Tostring
Uhhh...Me refers to the instance of the class it appears in. If you used Me inside a Form class, you executed .ToString() on a Form .
|
|
|
|
|
i made a delegate of one sub and sent its method.methodhandle.value to a sub in a VisualFortran Dll.
the sub in VisualFortran creates an interface to work with this sub and calling it from fortran.
this works in vb6 when i send the (addressof sub) to visual fortran but it does not work when the delegate.method.methodhandle.value in vb.net is sent to the fortran dll.
i know intptr is not even a CLS-Comapliant but i recieve the error "protected memory ..."
A.E.K
|
|
|
|
|
Without seeing your code that declares the delegate, the function your calling, and the callback function in your code, it's kind of hard to diagnose. This[^] is about the only thing anyone can recommend.
|
|
|
|
|
This is the code in VB.NET
Private Declare Function dll1 Lib "FileAddress" (ByVal ptr As Integer) as Single<br />
Public Delegate Function del1(ByVal p As Single) As Single<br />
Dim g1 As del1 = AddressOf proc1<br />
Function proc1(ByVal p As Single) As Single<br />
Return p ^ 2<br />
End Function
Here is the function Call(in.Net):
dll1(g1.Method.MethodHandle.Value)
and here the code in VisualFortran:
Real function dll1(F)<br />
!dec$ attributes dllexport ::dll1<br />
!dec$ attributes alias :'dll1'::dll1<br />
<br />
interface <br />
real function F(x)<br />
real x<br />
end<br />
end interface<br />
<br />
end
and I recieve this Error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Notice that i call back a function in .Net from Visual Fortran (not another .Net)
thanx a lot
A.E.K
|
|
|
|
|
Hi
I did an add-in for vs.NET 2003 and that element appeared in menu but I have a problem how to connect it with program I'd like to write. Which method is responsible for calling and where to set it? Could you help me or point out the webside with description?
Thank you for replays
Kasia
|
|
|
|
|
What is this "connection" supposed to do? What's it supposed to carry? What does this plugin do?
|
|
|
|
|
I added add-in into the menu. I don't know how to bind this with form. How to call it? Which method is responsible for doing it?
Katarzyna
|
|
|
|
|
You haven't answered any of my questions. The is information that anyone MUST have to tell you anything useful.
Katarzyna_ wrote: I don't know how to bind this with form.
A plugin to Visual Studio alters the functionality of Visual Studio, NOT your form.
Katarzyna_ wrote: How to call it? Which method is responsible for doing it?
Your projects code doesn't call an AddIn to Visual Studio. There's nothing to "bind" to. There is no one method for calling an Add In.
Or maybe I'm confused as to what this Add In is doing. It's impossible to say because you haven't said ANYTHING about what the plugin does.
|
|
|
|
|
I made an addin and it appeared in menu in Visual Studio. Now I'd like to have a possibility to choose that element in menu by click and call a form which I did. Simple path. Mayby it is imposible to do it. I just don't know.
I read about methods like:
OnConnection
OnDisconnection
OnStartupComplete
OnAddInsUpdate
OnBeginShutdown
but I don't know how to use it.
|
|
|
|
|
Which interface did you implement in your addin?
|
|
|
|
|
I've not implemented any interfaces in my addin yet because I don't know how to do it. It is just the problem I'd like sb to help me with.
|
|
|
|