By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

ADO.NET Problem write or wrong

P: n/a
I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field

End Sub
End Class
Dec 26 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
I am using sql 2005 and vb 2005

"Andrew" wrote:
I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field

End Sub
End Class
Dec 26 '06 #2

P: n/a
Andrew,

Nothing wrong with in my idea, however I would do it in its simplest format
in this way.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microsof t.com...
>I am simple tryint to learn how to use the ADO.NET code. Can anybody tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field

End Sub
End Class

Dec 26 '06 #3

P: n/a
Andrew wrote:
I am using sql 2005 and vb 2005

"Andrew" wrote:
I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me
if I am using it right or not?
<snip>

This worked for me: I first completely disregarded the several wizards
that come with VB 2005 and tried my hand in creating a strongly-typed
version of a database we have here. After struggling (and actually
succeeding) with this approach for a few days, I reckoned I had enough
control and knowledge of ADO.NET to give the designers a try. Currently
I'm using the designers for most new apps -- they're actually cool, if
you don't look under their dresses... =))

The experience with a hand-made strongly-typed db system tought me some
lessons and gave me a broarder perspective of the ADO.NET engine
workings. As they say, your mileage may vary. And it allowed me to
understand enough of it (I guess) to make it easier to extend the
functionality of the wizard generated items when necessary.

HTH.

Regards,

Branco.

Dec 26 '06 #4

P: n/a
Andrew,

Sorry, this can be
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microsof t.com...
when I put as you put I get an error : "System.data.datarow" cannot be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to instaance of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:
>Andrew,

Nothing wrong with in my idea, however I would do it in its simplest
format
in this way.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microso ft.com...
>I am simple tryint to learn how to use the ADO.NET code. Can anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field

End Sub
End Class



Dec 26 '06 #5

P: n/a
Andrew,
>I found one of the problems there was no (0) after Rows in my code, but now
when I execute I get the Exception error:
> Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)
I thought that I showed you that above. In what row is the exception error?.

Cor
>Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microso ft.com...
when I put as you put I get an error : "System.data.datarow" cannot be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microso ft.com...
I am simple tryint to learn how to use the ADO.NET code. Can anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in
field

End Sub
End Class



Dec 26 '06 #6

P: n/a

I had make a mistake and mistyped what you had. but the error is coming from
row 71 on my app, the same row were I have the da.fill(ds).

"Cor Ligthert [MVP]" wrote:
Andrew,
I found one of the problems there was no (0) after Rows in my code, but now
when I execute I get the Exception error:
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

I thought that I showed you that above. In what row is the exception error?.

Cor
Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microsof t.com...
when I put as you put I get an error : "System.data.datarow" cannot be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microsof t.com...
I am simple tryint to learn how to use the ADO.NET code. Can anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in
field

End Sub
End Class



Dec 26 '06 #7

P: n/a

Can you show your complete new code again,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:B3**********************************@microsof t.com...
>I think the error is coming from the:

da.fill(ds) ' function

"Cor Ligthert [MVP]" wrote:
>Andrew,

Sorry, this can be
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microso ft.com...
when I put as you put I get an error : "System.data.datarow" cannot be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microso ft.com...
I am simple tryint to learn how to use the ADO.NET code. Can anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in
field

End Sub
End Class



Dec 26 '06 #8

P: n/a
Instantiate da.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
here is the new code:
Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysMaster WHERE
sysName='IT_1'"
Dim da As SqlDataAdapter
Dim ds As New DataSet

Try
da.Fill(ds)

MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName ").ToString)
'trying to show what is in field
Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

End Sub
End Class

"Cor Ligthert [MVP]" wrote:
>>
Can you show your complete new code again,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:B3**********************************@microso ft.com...
>I think the error is coming from the:

da.fill(ds) ' function

"Cor Ligthert [MVP]" wrote:

Andrew,

Sorry, this can be
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microso ft.com...
when I put as you put I get an error : "System.data.datarow" cannot
be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to
instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its
simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName"))
'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microso ft.com...
I am simple tryint to learn how to use the ADO.NET code. Can
anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in
field

End Sub
End Class




Dec 26 '06 #9

P: n/a
You did it quite successfully in your original post.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
how would I do that in .net?

"Stephany Young" wrote:
>Instantiate da.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:0A**********************************@microso ft.com...
here is the new code:
Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysMaster WHERE
sysName='IT_1'"
Dim da As SqlDataAdapter
Dim ds As New DataSet

Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName ").ToString)
'trying to show what is in field
Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

End Sub
End Class

"Cor Ligthert [MVP]" wrote:
Can you show your complete new code again,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:B3**********************************@microso ft.com...
I think the error is coming from the:

da.fill(ds) ' function

"Cor Ligthert [MVP]" wrote:

Andrew,

Sorry, this can be
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microso ft.com...
when I put as you put I get an error : "System.data.datarow"
cannot
be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to
instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its
simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName"))
'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microso ft.com...
I am simple tryint to learn how to use the ADO.NET code. Can
anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is
in
field

End Sub
End Class





Dec 26 '06 #10

P: n/a
thanks for pointing that out, I was having a brian fart. At the time I got
this reply back I was noticing that there was no command execution for the
sql string. Not I am getting a reply back from the server, how ever I am not
use to loging in with windows authinication.

"Stephany Young" wrote:
You did it quite successfully in your original post.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
how would I do that in .net?

"Stephany Young" wrote:
Instantiate da.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
here is the new code:
Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysMaster WHERE
sysName='IT_1'"
Dim da As SqlDataAdapter
Dim ds As New DataSet

Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName ").ToString)
'trying to show what is in field
Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

End Sub
End Class

"Cor Ligthert [MVP]" wrote:


Can you show your complete new code again,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:B3**********************************@microsof t.com...
I think the error is coming from the:

da.fill(ds) ' function

"Cor Ligthert [MVP]" wrote:

Andrew,

Sorry, this can be
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microsof t.com...
when I put as you put I get an error : "System.data.datarow"
cannot
be
converted to string.

when I put convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to
instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its
simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName"))
'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:03**********************************@microsof t.com...
I am simple tryint to learn how to use the ADO.NET code. Can
anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what is
in
field

End Sub
End Class





Dec 26 '06 #11

P: n/a
When you are using the SqlClient objects, DO NOT include the Provider clause
in the connection string.

If you are using SQl Server authentication then the minimum connection
string is:

Data Source=<server>;Initial Catalog=<database>;User
ID=<username>;Password=<password>

where the tokens (<server>, <database>, <usernameand <password>) are
replaced with your own values.

The 'new' method for doing an insert is to instantiate a SqlCommand object
and call it's ExecuteNONQuery method:

Dim _con As New SqlConnection(_connectionstring)

Dim _com As New SqlCommand(_insertsqlstring, _con)

_com.Parameters.Add(_parametername, _parametertype).Value =
_parametervalue
' Add all required parameters

_con.Open()

_com.ExceuteNonQuery()

_con.Close()

I suggest you study the documentation relating to the
System.Data.SqlClient.SqlCommand class along with the documentation for
other related classes.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:AA**********************************@microsof t.com...
Thanks for pointing that out, I was having a brain fart. At the time I got
this reply back I was noticing that there was no command execution for the
sql string. Not I am getting a reply back from the server, how ever I am
not
use to logging in with windows authentication.

Is the provider string done the same way as in the previous version of
adodb. This is my string with the previous version

"Provider=SQLOLEDB.1;User ID=sa;password=" & sPassword & ";Initial
Catalog="
& sDBName & ";Data Source = " & sServer & ";Use Procedure for
Prepare=1;Auto
Translate=True;Packet Size=4096"

Is it the same in adodb.net or different?

and if I was to update a database through a sql string with this code, Do
I
do the same type of execution with the update sql string?

example of old:
cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO driveMaster
(driveID,sysID,evenID,driveDate,driveLET,driveTtl, driveFree)" & _
"VALUES (NEWID(), " & uID & ", 'ID3333', current_timestamp,
'" & sD & "', '" & iTtl & "', '" & iFree & "')"
cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
rs = cmd.Execute



"Stephany Young" wrote:
>You did it quite successfully in your original post.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:2E**********************************@microso ft.com...
how would I do that in .net?

"Stephany Young" wrote:

Instantiate da.
"Andrew" <An****@discussions.microsoft.comwrote in message
news:0A**********************************@microso ft.com...
here is the new code:
Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysMaster WHERE
sysName='IT_1'"
Dim da As SqlDataAdapter
Dim ds As New DataSet

Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName ").ToString)
'trying to show what is in field
Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

End Sub
End Class

"Cor Ligthert [MVP]" wrote:
Can you show your complete new code again,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:B3**********************************@microso ft.com...
I think the error is coming from the:

da.fill(ds) ' function

"Cor Ligthert [MVP]" wrote:

Andrew,

Sorry, this can be
Cstr(ds.Tables(0).Rows(0).Item("sysName"))
ds.Tables(0).Rows(0).Item("sysName").ToString
Ctype(ds.Tables(0).Rows(0).Item("sysName"),String)

Most people including me use the ToString,

I have typed it in the message, looking at the major points.

I hope it will go now, again not tested just typed.

Cor
"Andrew" <An****@discussions.microsoft.comschreef in bericht
news:07**********************************@microso ft.com...
when I put as you put I get an error : "System.data.datarow"
cannot
be
converted to string.

when I put
convert.tostring(ds.Tables(0).Rows.Item("sysName") ))

I get a new message:

system.nullfreferenceExecptoin: Object Reference not set to
instaance
of
an
Object.
as windowsApplication1.form1.button1_click() app path
ADodb.net\windowsaplication1\form1.vb:line71

I have one row with information in this table and the field is
a
nvarchar(max) with allow nulls checked.

"Cor Ligthert [MVP]" wrote:

Andrew,

Nothing wrong with in my idea, however I would do it in its
simplest
format
in this way.

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal
e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As new SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Try
da.Fill(ds)
MessageBox.Show(ds.Tables(0).Rows.Item("sysName"))
'trying
to
show
what is in field
Catch ex as Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

I hope this helps,

Cor
"Andrew" <An****@discussions.microsoft.comschreef in
bericht
news:03**********************************@microso ft.com...
I am simple tryint to learn how to use the ADO.NET code. Can
anybody
tell
me
if I am using it right or not?

Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal
e
As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated
Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysName"
Dim da As SqlDataAdapter
Dim ds As New DataSet
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
Dim dt As DataTable = ds.Tables(0)

MsgBox(dt.Rows.Item("sysName")) 'trying to show what
is
in
field

End Sub
End Class






Dec 26 '06 #12

P: n/a
>
Imports System.Data.sqlclient
Imports System.Data

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As New SqlConnection("Server=apw-db;" & _
"DataBase=APW-System; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM sysMaster WHERE
sysName='IT_1'"
Dim da As SqlDataAdapter
> Dim da As new SqlDataAdapter(sqlstr, conn)

Dec 27 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.