473,395 Members | 1,441 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,395 software developers and data experts.

Add rows from my flexgrid to a table

JFB
Hi All,
I have a edit flexgrid, after to fill with different rows manually.
How can I insert the rows of my flexgrid to my table (sql server) using
ado.net?
Any example?
I can insert one row with the code below but when I use a for loop to my
flexgrid... it doesn't work.
Also do you know any advance book for ado.net that you can recomend?
Tks in advance
JFB

Dim conn As New SqlConnection(connectionString)
'Dim insertSQL As String = "INSERT INTO
Orders(customerID,houseID,orderDate,description,em ployeeID,invoiceStatus)val
ues(@customerID,@houseID,@orderDate,@description,@ employeeID,@invoiceStatus)
"

Dim cmd As New SqlCommand(insertSQL, conn)

Dim i As Integer

Dim Param As SqlParameter

For i = 1 To ordersFG.Rows.Count - 2

'Add the input parameters

Param = cmd.Parameters.Add("@customerID", SqlDbType.Int, 4)

Param.Value = ordersFG(i, 1)

Param = cmd.Parameters.Add("@houseID", SqlDbType.Int, 4)

Param.Value = ordersFG(i, 2)

Param = cmd.Parameters.Add("@orderDate", SqlDbType.SmallDateTime, 4)

Param.Value = ordersFG(i, 3)

Param = cmd.Parameters.Add("@employeeID", SqlDbType.Int, 4)

Param.Value = ordersFG(i, 4)

Param = cmd.Parameters.Add("@description", SqlDbType.VarChar, 255)

Param.Value = ordersFG(i, 5)

Param = cmd.Parameters.Add("@invoiceStatus", SqlDbType.Bit, 1)

Param.Value = 0

Next

Try

'Execute command

conn.Open()

Dim rows As Integer = cmd.ExecuteNonQuery

'Clear the flexgrid data

Dim rowCount

rowCount = ordersFG.Rows.Count

ordersFG.Rows.Count = ordersFG.Rows.Fixed

MsgBox("Data is already SAVE")

Catch ex As Exception

MsgBox(ex.ToString)

Return

Finally

conn.Close()

End Try
Nov 20 '05 #1
9 5524
Cor
Hi JFB,

That people are using the Flexgrid without a data connection is something I
can understand.
(Althoug not necessary)

But using the Flexgrid instead of the datagrid with a database is for me not
understandable.

Helping you with that is in my idea bringing you in the wrong direction to
the solution

Just my thougth,

Cor
Nov 20 '05 #2
JFB
Hi Cor,
Tks for you reply...
mmmm.... why?
My flexgrid is for edith (combo box with dataset, datetimepicker...) and
validate the data before to insert to my table.
It doesn't makes sence?
I dont want to pull any data, that's why I'm not using datagrid, I want to
insert data to my table.
am I wrong? Can you explain more to me?
JFB

"Cor" <no*@non.com> wrote in message
news:O6**************@TK2MSFTNGP10.phx.gbl...
Hi JFB,

That people are using the Flexgrid without a data connection is something I can understand.
(Althoug not necessary)

But using the Flexgrid instead of the datagrid with a database is for me not understandable.

Helping you with that is in my idea bringing you in the wrong direction to
the solution

Just my thougth,

Cor

Nov 20 '05 #3
Cor
Hi JFB,

I do not know which flexgrid you are using.

But a datagrid you can bind to a datatable, dataset, dataview
(a datatable is easy to made in your program)

You can bind it (using the datasource) the only extra thing is to make
something to delete rows, inserting is a part of it.

When you bind it to a readed (filled) dataset than all changes are
registrated and you can do a simple dataadapter update of the datasettable
to write it back to the dataset.

It has a lot posibilities for styles (datagridstyles and
datagridcolumnstyles)

But see this introduction.

http://msdn.microsoft.com/library/de...ridcontrol.asp

I hope this gives some idea's?

Cor
Nov 20 '05 #4
JFB
Tks for reply and help Cor,
Now we are talking... I think I got the picture but not the code.
How can insert the rows to the dataset?

JFB
'Fill dataSet with orders table (I dont want to do it because I dont want to
retrieve any data)

cmdSQL.CommandText = "Select * from orders"

hAdapter.SelectCommand = cmdSQL

hAdapter.Fill(hSet, "orders")

'Here is the problem

hSet.Tables(0).Rows(myFlexgrid. ??? ).insert ????

'To update the adapter

hAdapter.update(hSet)


"Cor" <no*@non.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
Hi JFB,

I do not know which flexgrid you are using.

But a datagrid you can bind to a datatable, dataset, dataview
(a datatable is easy to made in your program)

You can bind it (using the datasource) the only extra thing is to make
something to delete rows, inserting is a part of it.

When you bind it to a readed (filled) dataset than all changes are
registrated and you can do a simple dataadapter update of the datasettable
to write it back to the dataset.

It has a lot posibilities for styles (datagridstyles and
datagridcolumnstyles)

But see this introduction.

http://msdn.microsoft.com/library/de...ridcontrol.asp
I hope this gives some idea's?

Cor

Nov 20 '05 #5
Cor
Hi JFB,

Asuming that you can want to process the items from the flexgrid I do this
in psuedo because I do not know the flexgrid.

To fill the flexgrid (I hope this is posible)
\\\as far as the flexgrid pseudo the rest maybe typos but further probably
correct
dim i as integer
dim y as integer
for i = 0 to hset.tables(0).rows.count-1
for y = 0 to hset.tables(0).columns.count - 1
flexgrid.row(i).item(y) = hset.tables(0).rows(i).(y)
next
next
///
If you do not use a part of the for loop with the y you also can do
\\\
flexgrid.row(i).itemx = hset.tables(0).rows(i).item("itemx")
///
How to update the dataset from the flexgrid I think that that you should
find out first yourself because that is just how you use it. But you have to
do that with every event in the flexgrid.

And keep in mind not to use the "remove" method from the dataset.

I hope this helps?

Cor
"> Tks for reply and help Cor,
Now we are talking... I think I got the picture but not the code.
How can insert the rows to the dataset?

JFB
'Fill dataSet with orders table (I dont want to do it because I dont want to retrieve any data)

cmdSQL.CommandText = "Select * from orders"

hAdapter.SelectCommand = cmdSQL

hAdapter.Fill(hSet, "orders")

'Here is the problem

hSet.Tables(0).Rows(myFlexgrid. ??? ).insert ????

'To update the adapter

hAdapter.update(hSet)

Nov 20 '05 #6
JFB
Cor I forgot to tell you that this flexgrid has the same properties as
datagrid.
How do you update the dataset with you datagrid?
Tks again
JFB

"Cor" <no*@non.com> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
Hi JFB,

Asuming that you can want to process the items from the flexgrid I do this
in psuedo because I do not know the flexgrid.

To fill the flexgrid (I hope this is posible)
\\\as far as the flexgrid pseudo the rest maybe typos but further probably
correct
dim i as integer
dim y as integer
for i = 0 to hset.tables(0).rows.count-1
for y = 0 to hset.tables(0).columns.count - 1
flexgrid.row(i).item(y) = hset.tables(0).rows(i).(y)
next
next
///
If you do not use a part of the for loop with the y you also can do
\\\
flexgrid.row(i).itemx = hset.tables(0).rows(i).item("itemx")
///
How to update the dataset from the flexgrid I think that that you should
find out first yourself because that is just how you use it. But you have to do that with every event in the flexgrid.

And keep in mind not to use the "remove" method from the dataset.

I hope this helps?

Cor
"> Tks for reply and help Cor,
Now we are talking... I think I got the picture but not the code.
How can insert the rows to the dataset?

JFB
'Fill dataSet with orders table (I dont want to do it because I dont
want to
retrieve any data)

cmdSQL.CommandText = "Select * from orders"

hAdapter.SelectCommand = cmdSQL

hAdapter.Fill(hSet, "orders")

'Here is the problem

hSet.Tables(0).Rows(myFlexgrid. ??? ).insert ????

'To update the adapter

hAdapter.update(hSet)


Nov 20 '05 #7
Cor
Hi JFB

Basicly, just bind it and than you do not have to do that for each loop to
fill it either, something like
\\\
dg.datasource=hset.tables(0)
///
And then
\\\
DirectCast(BindingContext(hset.Tables(0)), CurrencyManager).EndCurrentEdit()
///
Before
\\\
hAdapter.update(hSet)
///
The last can nicer have for that a look to haschanges and getchanges.

I hope this helps?

Cor
Cor I forgot to tell you that this flexgrid has the same properties as
datagrid.
How do you update the dataset with you datagrid?
Tks again
JFB

"Cor" <no*@non.com> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
Hi JFB,

Asuming that you can want to process the items from the flexgrid I do this in psuedo because I do not know the flexgrid.

To fill the flexgrid (I hope this is posible)
\\\as far as the flexgrid pseudo the rest maybe typos but further probably correct
dim i as integer
dim y as integer
for i = 0 to hset.tables(0).rows.count-1
for y = 0 to hset.tables(0).columns.count - 1
flexgrid.row(i).item(y) = hset.tables(0).rows(i).(y)
next
next
///
If you do not use a part of the for loop with the y you also can do
\\\
flexgrid.row(i).itemx = hset.tables(0).rows(i).item("itemx")
///
How to update the dataset from the flexgrid I think that that you should
find out first yourself because that is just how you use it. But you
have to
do that with every event in the flexgrid.

And keep in mind not to use the "remove" method from the dataset.

I hope this helps?

Cor
"> Tks for reply and help Cor,
Now we are talking... I think I got the picture but not the code.
How can insert the rows to the dataset?

JFB
'Fill dataSet with orders table (I dont want to do it because I dont

want
to
retrieve any data)

cmdSQL.CommandText = "Select * from orders"

hAdapter.SelectCommand = cmdSQL

hAdapter.Fill(hSet, "orders")

'Here is the problem

hSet.Tables(0).Rows(myFlexgrid. ??? ).insert ????

'To update the adapter

hAdapter.update(hSet)



Nov 20 '05 #8
JFB
FYI... I found the solution over the weekend reading the SQL Server Magazine
InstantDoc ID 40791-Listing2.
This solution in not like you suggest as one line code but it works for
me now.
Part of the problem with you suggestion is that I dont have the
invoiceStatus column in my flexgrid and I have to setup this value as zero.
Tks again
JFB

Dim conn As New SqlConnection(connectionString)

Dim insertSQL As String = "INSERT INTO
Orders(customerID,houseID,orderDate,description,em ployeeID,invoiceStatus)val
ues(@customerID,@houseID,@orderDate,@description,@ employeeID,@invoiceStatus)
"

Dim cmd As New SqlCommand(insertSQL, conn)

'Declaring all the input parameters

Dim parmCustomerID = New SqlParameter("@customerID", SqlDbType.Int, 4)

parmCustomerID.direction = ParameterDirection.Input

Dim parmHouseID = New SqlParameter("@houseID", SqlDbType.Int, 4)

parmHouseID.direction = ParameterDirection.Input

Dim parmOrderDate = New SqlParameter("@orderDate", SqlDbType.SmallDateTime,
4)

parmHouseID.direction = ParameterDirection.Input

Dim parmEmployeeID = New SqlParameter("@employeeID", SqlDbType.Int, 4)

parmEmployeeID.direction = ParameterDirection.Input

Dim parmDescription = New SqlParameter("@description", SqlDbType.VarChar,
255)

parmDescription.direction = ParameterDirection.Input

Dim parmInvoiceStatus = New SqlParameter("@invoiceStatus", SqlDbType.Bit, 1)

parmInvoiceStatus.direction = ParameterDirection.Input

'Add the parameter objects to the cmd parameter collection

cmd.Parameters.Add(parmCustomerID)

cmd.Parameters.Add(parmHouseID)

cmd.Parameters.Add(parmOrderDate)

cmd.Parameters.Add(parmEmployeeID)

cmd.Parameters.Add(parmDescription)

cmd.Parameters.Add(parminvoicestatus)

Try

conn.Open()

cmd.Prepare()

Dim i As Integer

For i = 1 To ordersFG.Rows.Count - 2

'Add the values to the parameters

parmCustomerID.value = ordersFG(i, 1)

parmHouseID.Value = ordersFG(i, 2)

parmOrderDate.Value = ordersFG(i, 3)

parmEmployeeID.Value = ordersFG(i, 4)

parmDescription.Value = ordersFG(i, 5)

parmInvoiceStatus.Value = 0

cmd.ExecuteNonQuery()

Next

Catch ex As Exception

MsgBox(ex.ToString)

Return

Finally

conn.Close()

End Try

"Cor" <no*@non.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
Hi JFB

Basicly, just bind it and than you do not have to do that for each loop to
fill it either, something like
\\\
dg.datasource=hset.tables(0)
///
And then
\\\
DirectCast(BindingContext(hset.Tables(0)), CurrencyManager).EndCurrentEdit() ///
Before
\\\
hAdapter.update(hSet)
///
The last can nicer have for that a look to haschanges and getchanges.

I hope this helps?

Cor
Cor I forgot to tell you that this flexgrid has the same properties as
datagrid.
How do you update the dataset with you datagrid?
Tks again
JFB

"Cor" <no*@non.com> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
Hi JFB,

Asuming that you can want to process the items from the flexgrid I do this in psuedo because I do not know the flexgrid.

To fill the flexgrid (I hope this is posible)
\\\as far as the flexgrid pseudo the rest maybe typos but further probably correct
dim i as integer
dim y as integer
for i = 0 to hset.tables(0).rows.count-1
for y = 0 to hset.tables(0).columns.count - 1
flexgrid.row(i).item(y) = hset.tables(0).rows(i).(y)
next
next
///
If you do not use a part of the for loop with the y you also can do
\\\
flexgrid.row(i).itemx = hset.tables(0).rows(i).item("itemx")
///
How to update the dataset from the flexgrid I think that that you should find out first yourself because that is just how you use it. But you

have
to
do that with every event in the flexgrid.

And keep in mind not to use the "remove" method from the dataset.

I hope this helps?

Cor
"> Tks for reply and help Cor,
> Now we are talking... I think I got the picture but not the code.
> How can insert the rows to the dataset?
>
> JFB
> 'Fill dataSet with orders table (I dont want to do it because I dont

want
to
> retrieve any data)
>
> cmdSQL.CommandText = "Select * from orders"
>
> hAdapter.SelectCommand = cmdSQL
>
> hAdapter.Fill(hSet, "orders")
>
> 'Here is the problem
>
> hSet.Tables(0).Rows(myFlexgrid. ??? ).insert ????
>
> 'To update the adapter
>
> hAdapter.update(hSet)
>
>
>
>



Nov 20 '05 #9
JFB
FYI... I found the solution over the weekend reading the SQL Server Magazine
InstantDoc ID 40791-Listing2.
This solution in not like you suggest as one line code but it works for
me now.
Part of the problem with you suggestion is that I dont have the
invoiceStatus column in my flexgrid and I have to setup this value as zero.
Tks again
JFB

Dim conn As New SqlConnection(connectionString)

Dim insertSQL As String = "INSERT INTO
Orders(customerID,houseID,orderDate,description,em ployeeID,invoiceStatus)val
ues(@customerID,@houseID,@orderDate,@description,@ employeeID,@invoiceStatus)
"

Dim cmd As New SqlCommand(insertSQL, conn)

'Declaring all the input parameters

Dim parmCustomerID = New SqlParameter("@customerID", SqlDbType.Int, 4)

parmCustomerID.direction = ParameterDirection.Input

Dim parmHouseID = New SqlParameter("@houseID", SqlDbType.Int, 4)

parmHouseID.direction = ParameterDirection.Input

Dim parmOrderDate = New SqlParameter("@orderDate", SqlDbType.SmallDateTime,
4)

parmHouseID.direction = ParameterDirection.Input

Dim parmEmployeeID = New SqlParameter("@employeeID", SqlDbType.Int, 4)

parmEmployeeID.direction = ParameterDirection.Input

Dim parmDescription = New SqlParameter("@description", SqlDbType.VarChar,
255)

parmDescription.direction = ParameterDirection.Input

Dim parmInvoiceStatus = New SqlParameter("@invoiceStatus", SqlDbType.Bit, 1)

parmInvoiceStatus.direction = ParameterDirection.Input

'Add the parameter objects to the cmd parameter collection

cmd.Parameters.Add(parmCustomerID)

cmd.Parameters.Add(parmHouseID)

cmd.Parameters.Add(parmOrderDate)

cmd.Parameters.Add(parmEmployeeID)

cmd.Parameters.Add(parmDescription)

cmd.Parameters.Add(parminvoicestatus)

Try

conn.Open()

cmd.Prepare()

Dim i As Integer

For i = 1 To ordersFG.Rows.Count - 2

'Add the values to the parameters

parmCustomerID.value = ordersFG(i, 1)

parmHouseID.Value = ordersFG(i, 2)

parmOrderDate.Value = ordersFG(i, 3)

parmEmployeeID.Value = ordersFG(i, 4)

parmDescription.Value = ordersFG(i, 5)

parmInvoiceStatus.Value = 0

cmd.ExecuteNonQuery()

Next

Catch ex As Exception

MsgBox(ex.ToString)

Return

Finally

conn.Close()

End Try

"Cor" <no*@non.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
Hi JFB

Basicly, just bind it and than you do not have to do that for each loop to
fill it either, something like
\\\
dg.datasource=hset.tables(0)
///
And then
\\\
DirectCast(BindingContext(hset.Tables(0)), CurrencyManager).EndCurrentEdit() ///
Before
\\\
hAdapter.update(hSet)
///
The last can nicer have for that a look to haschanges and getchanges.

I hope this helps?

Cor
Cor I forgot to tell you that this flexgrid has the same properties as
datagrid.
How do you update the dataset with you datagrid?
Tks again
JFB

"Cor" <no*@non.com> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
Hi JFB,

Asuming that you can want to process the items from the flexgrid I do this in psuedo because I do not know the flexgrid.

To fill the flexgrid (I hope this is posible)
\\\as far as the flexgrid pseudo the rest maybe typos but further probably correct
dim i as integer
dim y as integer
for i = 0 to hset.tables(0).rows.count-1
for y = 0 to hset.tables(0).columns.count - 1
flexgrid.row(i).item(y) = hset.tables(0).rows(i).(y)
next
next
///
If you do not use a part of the for loop with the y you also can do
\\\
flexgrid.row(i).itemx = hset.tables(0).rows(i).item("itemx")
///
How to update the dataset from the flexgrid I think that that you should find out first yourself because that is just how you use it. But you

have
to
do that with every event in the flexgrid.

And keep in mind not to use the "remove" method from the dataset.

I hope this helps?

Cor
"> Tks for reply and help Cor,
> Now we are talking... I think I got the picture but not the code.
> How can insert the rows to the dataset?
>
> JFB
> 'Fill dataSet with orders table (I dont want to do it because I dont

want
to
> retrieve any data)
>
> cmdSQL.CommandText = "Select * from orders"
>
> hAdapter.SelectCommand = cmdSQL
>
> hAdapter.Fill(hSet, "orders")
>
> 'Here is the problem
>
> hSet.Tables(0).Rows(myFlexgrid. ??? ).insert ????
>
> 'To update the adapter
>
> hAdapter.update(hSet)
>
>
>
>



Nov 20 '05 #10

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

Similar topics

7
by: tombsy | last post by:
Hi gang... I want to have a form that can display data from a datasource that is not fixed. lets say a crosstab query that can change the number of colums and field headings depending on the...
4
by: VR | last post by:
I am trying to embed a check box into a FlexGrid's cell, but having a problem when I start scrolling the grid. Here is my MyCheckBox class... class MyCheckBox : CheckBox { void Init (...
6
by: fripper | last post by:
I have just purchased a new system and am moving stuff off the old machine to the new ... including reinstalling VS .Net 2003 and several VB programs I had written. One of the programs uses a...
4
by: fripper | last post by:
I have replaced an older machine with a new one and have moved a VB .Net program that I worte on the old machine to the new one. The program uses a FlexGrid control for displaying some stuff in a...
5
by: schapopa | last post by:
I have a flex grid and I am loading data to this flex grid in this way While sqldr.Read j = j + 1 MSFlexGrid1PLSummary.set_TextMatrix(MSFlexGrid1PLSummary.Row, MSFlexGrid1PLSummary.Col,...
0
by: alexh1000 | last post by:
When I insert the FlexGrid control in a dialog (using controls toolbar) the dialog fails to open on program execution(DoModal returns a -1). If I remove the FlexGrid from the dialog, the dialog...
1
by: kasthuriii | last post by:
please tell me how to add and delete rows and columns in flexgrid in vb.net. please give me some sample programs using flexgrid if possible.
0
by: chirayushbpatel | last post by:
I use flexgrid control in my VB apllication but I cant get data from MS Access database, an error dispaly like "Unrecognized databse format" How can I get table data in flexgrid control
3
by: sweevil | last post by:
I'm converting a VB6 project to .Net2005. One of the items encountered was setting the cellpicture onto a flexgrid from an imagelist. The image background doesn't appear to render correctly. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.