Showing posts with label fill. Show all posts
Showing posts with label fill. Show all posts

Saturday, February 25, 2012

Newbie - SqlConnection statement

I'm trying to get a combobox to fill with values from a table. I've
set up an example using the Northwind database with the Categories
table. Dragging in the CategoryID field onto my form as a combobox,
I've set the following properties for the CategoryID combobox:
Value member = "CategoriesBindingSource - CategoryID"
Display Member = "CategoriesBindingSource - CategoryID"
This seems to bring in the correct values in the two non-index fields
(CategoryName and Description). I've then added the following code to
the combobox:
Dim Conn As SqlConnection
Conn = New SqlConnection("Database=Northwnd.mdf")
'Conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT
CategoryID FROM Categories", Conn)
Dim ds As New DataSet
da.Fill(ds, "Categories")
CategoryIDComboBox.DataSource = ds
'CategoryIDComboBox.ValueMember = "CategoryID"
'CategoryIDComboBox.DisplayMember = "CategoryID"
End Sub
The lines that are commented out are other ideas that I've tried to no
avail. I left them here in case they are relevant.
I suspect that at least part of my problem is in the SqlDataAdapter
statement where I am pointing to the database. I am working on a
standalone pc.
Can anybody see where I am going wrong?
Thanks,
RandyHi Randy
"Randy" wrote:

> I'm trying to get a combobox to fill with values from a table. I've
> set up an example using the Northwind database with the Categories
> table. Dragging in the CategoryID field onto my form as a combobox,
> I've set the following properties for the CategoryID combobox:
> Value member = "CategoriesBindingSource - CategoryID"
> Display Member = "CategoriesBindingSource - CategoryID"
> This seems to bring in the correct values in the two non-index fields
> (CategoryName and Description). I've then added the following code to
> the combobox:
> Dim Conn As SqlConnection
> Conn = New SqlConnection("Database=Northwnd.mdf")
> 'Conn.Open()
> Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT
> CategoryID FROM Categories", Conn)
> Dim ds As New DataSet
> da.Fill(ds, "Categories")
> CategoryIDComboBox.DataSource = ds
> 'CategoryIDComboBox.ValueMember = "CategoryID"
> 'CategoryIDComboBox.DisplayMember = "CategoryID"
> End Sub
> The lines that are commented out are other ideas that I've tried to no
> avail. I left them here in case they are relevant.
> I suspect that at least part of my problem is in the SqlDataAdapter
> statement where I am pointing to the database. I am working on a
> standalone pc.
> Can anybody see where I am going wrong?
> Thanks,
> Randy
>
For connection string information check out
http://www.connectionstrings.com/?carrier=sqlserver2005
You may also want to some of the examples such as
http://msdn.microsoft.com/library/d...opi
c.asp
John

Newbie - SqlConnection statement

I'm trying to get a combobox to fill with values from a table. I've
set up an example using the Northwind database with the Categories
table. Dragging in the CategoryID field onto my form as a combobox,
I've set the following properties for the CategoryID combobox:
Value member = "CategoriesBindingSource - CategoryID"
Display Member = "CategoriesBindingSource - CategoryID"
This seems to bring in the correct values in the two non-index fields
(CategoryName and Description). I've then added the following code to
the combobox:
Dim Conn As SqlConnection
Conn = New SqlConnection("Database=Northwnd.mdf")
'Conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT
CategoryID FROM Categories", Conn)
Dim ds As New DataSet
da.Fill(ds, "Categories")
CategoryIDComboBox.DataSource = ds
'CategoryIDComboBox.ValueMember = "CategoryID"
'CategoryIDComboBox.DisplayMember = "CategoryID"
End Sub
The lines that are commented out are other ideas that I've tried to no
avail. I left them here in case they are relevant.
I suspect that at least part of my problem is in the SqlDataAdapter
statement where I am pointing to the database. I am working on a
standalone pc.
Can anybody see where I am going wrong?
Thanks,
Randy
Hi Randy
"Randy" wrote:

> I'm trying to get a combobox to fill with values from a table. I've
> set up an example using the Northwind database with the Categories
> table. Dragging in the CategoryID field onto my form as a combobox,
> I've set the following properties for the CategoryID combobox:
> Value member = "CategoriesBindingSource - CategoryID"
> Display Member = "CategoriesBindingSource - CategoryID"
> This seems to bring in the correct values in the two non-index fields
> (CategoryName and Description). I've then added the following code to
> the combobox:
> Dim Conn As SqlConnection
> Conn = New SqlConnection("Database=Northwnd.mdf")
> 'Conn.Open()
> Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT
> CategoryID FROM Categories", Conn)
> Dim ds As New DataSet
> da.Fill(ds, "Categories")
> CategoryIDComboBox.DataSource = ds
> 'CategoryIDComboBox.ValueMember = "CategoryID"
> 'CategoryIDComboBox.DisplayMember = "CategoryID"
> End Sub
> The lines that are commented out are other ideas that I've tried to no
> avail. I left them here in case they are relevant.
> I suspect that at least part of my problem is in the SqlDataAdapter
> statement where I am pointing to the database. I am working on a
> standalone pc.
> Can anybody see where I am going wrong?
> Thanks,
> Randy
>
For connection string information check out
http://www.connectionstrings.com/?carrier=sqlserver2005
You may also want to some of the examples such as
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlconnectionclasstopic.as p[/url]
John

Newbie - SqlConnection statement

I'm trying to get a combobox to fill with values from a table. I've
set up an example using the Northwind database with the Categories
table. Dragging in the CategoryID field onto my form as a combobox,
I've set the following properties for the CategoryID combobox:
Value member = "CategoriesBindingSource - CategoryID"
Display Member = "CategoriesBindingSource - CategoryID"
This seems to bring in the correct values in the two non-index fields
(CategoryName and Description). I've then added the following code to
the combobox:
Dim Conn As SqlConnection
Conn = New SqlConnection("Database=Northwnd.mdf")
'Conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT
CategoryID FROM Categories", Conn)
Dim ds As New DataSet
da.Fill(ds, "Categories")
CategoryIDComboBox.DataSource = ds
'CategoryIDComboBox.ValueMember = "CategoryID"
'CategoryIDComboBox.DisplayMember = "CategoryID"
End Sub
The lines that are commented out are other ideas that I've tried to no
avail. I left them here in case they are relevant.
I suspect that at least part of my problem is in the SqlDataAdapter
statement where I am pointing to the database. I am working on a
standalone pc.
Can anybody see where I am going wrong?
Thanks,
RandyHi Randy
"Randy" wrote:
> I'm trying to get a combobox to fill with values from a table. I've
> set up an example using the Northwind database with the Categories
> table. Dragging in the CategoryID field onto my form as a combobox,
> I've set the following properties for the CategoryID combobox:
> Value member = "CategoriesBindingSource - CategoryID"
> Display Member = "CategoriesBindingSource - CategoryID"
> This seems to bring in the correct values in the two non-index fields
> (CategoryName and Description). I've then added the following code to
> the combobox:
> Dim Conn As SqlConnection
> Conn = New SqlConnection("Database=Northwnd.mdf")
> 'Conn.Open()
> Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT
> CategoryID FROM Categories", Conn)
> Dim ds As New DataSet
> da.Fill(ds, "Categories")
> CategoryIDComboBox.DataSource = ds
> 'CategoryIDComboBox.ValueMember = "CategoryID"
> 'CategoryIDComboBox.DisplayMember = "CategoryID"
> End Sub
> The lines that are commented out are other ideas that I've tried to no
> avail. I left them here in case they are relevant.
> I suspect that at least part of my problem is in the SqlDataAdapter
> statement where I am pointing to the database. I am working on a
> standalone pc.
> Can anybody see where I am going wrong?
> Thanks,
> Randy
>
For connection string information check out
http://www.connectionstrings.com/?carrier=sqlserver2005
You may also want to some of the examples such as
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlconnectionclasstopic.asp
John

Newbie - Program

This is my first foray into MS SQL Server, so I am trying to get my feet wet
with a couple of things. One thing I am trying to do right now is fill in a
uniqueidentifier field I added to a table using the NEWID() function. In MS
Access, I would have cranked out a little VBA code that simply went through
all the records in the table one by one and setting the Record_ID (type
uniqueidentifier) field using NEWID().
Unfortunately, I don't have a warm and fuzzy on how to accomplish this
within SQL Server itself. Best I have been able to tell so far, I probably
want to be developing a procedure. But I am not sure how to accomplish what
I want to do using SQL.
Suggestions and pointers to references will be greatly appreciated!
Thanks!
DonHello, Don
You only need:
UPDATE YourTable SET YourColumn=NEWID()
That's because the NEWID() function will be called for each row
(therefore you will get a different value in each row).
Razvan|||In SQL server there is a thing called default value
You will see it in Enterprise Manager when you click on design table
In the default value property of a field you can type newid() and whenever a
new record is inserted it will 'automatically' get this value
Default values are very handy for Created Date you would give it a default
value of getdate()
Hope this helped you and did not add to the confusion
http://sqlservercode.blogspot.com/
"Don" wrote:

> This is my first foray into MS SQL Server, so I am trying to get my feet w
et
> with a couple of things. One thing I am trying to do right now is fill in
a
> uniqueidentifier field I added to a table using the NEWID() function. In
MS
> Access, I would have cranked out a little VBA code that simply went throug
h
> all the records in the table one by one and setting the Record_ID (type
> uniqueidentifier) field using NEWID().
> Unfortunately, I don't have a warm and fuzzy on how to accomplish this
> within SQL Server itself. Best I have been able to tell so far, I probabl
y
> want to be developing a procedure. But I am not sure how to accomplish wh
at
> I want to do using SQL.
> Suggestions and pointers to references will be greatly appreciated!
> Thanks!
> Don
>
>
>|||SQL,
While I was playing around, I discovered the default value and that if you
select that property when you create the field it will automatically fill in
values! In my first attempt, I had created the field, but not set the
default value so I had a table full of <Null> for that field (never mind the
issue of adding a new record later!).
Thanks for the help!!
Don
"SQL" <SQL@.discussions.microsoft.com> wrote in message
news:75975E43-A123-43DC-96C3-B120D0B35BF0@.microsoft.com...
> In SQL server there is a thing called default value
> You will see it in Enterprise Manager when you click on design table
> In the default value property of a field you can type newid() and whenever
> a
> new record is inserted it will 'automatically' get this value
> Default values are very handy for Created Date you would give it a default
> value of getdate()
> Hope this helped you and did not add to the confusion
> http://sqlservercode.blogspot.com/
>
> "Don" wrote:
>|||Razvan,
I actually solved my immediate problem a little differently, but your
suggestion will definitely help in the future!!
Thanks!
Don
"Razvan Socol" <rsocol@.gmail.com> wrote in message
news:1127663811.868041.231450@.g43g2000cwa.googlegroups.com...
> Hello, Don
> You only need:
> UPDATE YourTable SET YourColumn=NEWID()
> That's because the NEWID() function will be called for each row
> (therefore you will get a different value in each row).
> Razvan
>|||Your entire mental model of SQL and RDBMS is totally wrong and will
take at least one year of solid work to change. This is based on 20+
years with SQL and teaching it.
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files; there is no sequential access or
ordering in an RDBMS, so "first", "next" and "last" are totally
meaningless. NEWID and uniqueidentifier "field" are proprietary,
non-relational crap. Since you started with ACCESS, you need to add an
extra six months of UN-learning.
A newsgroup is a piss poor substitue for an education. Please read
something before you post again.

Newbie - Filling Tables with Data

Hi

I am writing SQL scripts to define my tables and also fill some of them with
data that are essentially look up tables. One of the tables contains
hundreds of stock items which need to be filled with information.

Is it better to write my INSERT INTO... statements to fill this large table
or better to manually insert the data??

As this solution will be for a small jewellery store which has many
locations and the users cannot be assumed to be advanced-level users, are
there any advantages to writing scripts to fill the tables? (Will be using
MSDE when shipped)

TIA
MichelleI suppose it depends on the user interface you would use to input the data.
Use whichever is quickest and easiest. If you later need to create a script
of INSERT INTO statements you can use this code:
http://vyaskn.tripod.com/code.htm#inserts

Also, consider using DTS to import the data if you have some alternative
electronic source of the data.

--
David Portas
SQL Server MVP
--|||Thank you David for your reply and for the great link also.

No doubt it won't be the last post I put on here.

Michelle

"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:76mdnaugYLHpzS3d4p2dnA@.giganews.com...
> I suppose it depends on the user interface you would use to input the
data.
> Use whichever is quickest and easiest. If you later need to create a
script
> of INSERT INTO statements you can use this code:
> http://vyaskn.tripod.com/code.htm#inserts
> Also, consider using DTS to import the data if you have some alternative
> electronic source of the data.
> --
> David Portas
> SQL Server MVP
> --