473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ADO.NET Problem write or wrong

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
12 1334
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
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
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
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
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

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

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
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
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
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
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
>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hijwel | last post by:
<script language="JavaScript"> <!-- document.write('<form name="combo"><select name="example" size="1 onChange="Draw()">'); document.write('<option value=none>Maak je keuze');...
11
by: Pflanzen Gold | last post by:
Hi, When entering a password we don't really see the characters - we see **** instead. How can I write such a routine in C? How can I 'echo off' the inputs? How can I get a characters/strings...
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
1
by: Michael C | last post by:
Someone at work told me that he has estimated it is taking him 5 to 10 times longer to write an app as a web app instead of windows app. He's been working on it for 18 months and reckons he could...
22
by: EMW | last post by:
Hi, When I use Response.Write "something" it is placed at the top op de html document above the <HTML> tag. I need it to be put in the BODY part. How can I do this? rg,
2
by: ykgoh | last post by:
Hi. I've a problem of being able to create and remove a directory but unable to write a file inside the created directory for some strange reason. I suspect that this problem could be vaguely...
10
by: Geoff | last post by:
I am using the following statement in a script: If (res == 123) document.write (" Blah Blah"); else document.write (" XYZ"); This of course brings up a new page on my site and prints Blah...
8
by: mohammaditraders | last post by:
#include <iostream.h> #include <stdlib.h> #include <conio.h> #include <string.h> class Matrix { private : int numRows, numCols ; int elements ;
13
by: zach | last post by:
Can someone help me out, I can't figure out what I'm doing wrong to write to a file in binary mode. What's wrong with my code? <?php $fileName = "something.dat"; $string = "This is a...
0
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.