Hi Varun,
Nothing wrong but I did type a lot, just to make it better and also in a way
you can next time make a webapplication from it (that is not the reason),
then they can hire your cars at home.
I am creating a single user application. By the sounds of it i am doing
what u suggest already. I think anyway!!! This is what im doing..
there are 5 controls on form:
1) DateTimePicker (dtp)
2) Combobox1 - to select a carmake (filled using a datareader)
Use a dataset, it is so easy to use
Your connection stays the same
Your select becomes something as (or stored procedure)
dim sqlString = "SELECT DISTINCT markes FROM cars WHERE date = @date ORDER
BY markes" (I am really someone who hates SQL, so that part you have to
check extra).
you fill the commandparameters just the same as you did before with the
dates from the datareader
then
dim ds1 as new dataset
dim da as new Sqlclient.SqlDataAdapter(theCommand)
da.fill(ds1)
me.combobox1.datasource = nothing 'that is for the secondtime you set it.
me.combobox1.datasource =ds1.tables(0)
me.combobox1.displaymember = "markes"
3) Combobox2 - to select the car registrations that are availble for the
carmake and date specifed. I created a stored procedure with the carmake and
date as parameters to only show the registrations that are available. This
combobox is filled using a datareader once the stored procedure has been
run.
When the mark is choosen,
you fill the commandparameters
dim sqlString = "SELECT * FROM cars WHERE date = @date AND mark = @mark
ORDER BY regs"
you fill the commandparameters and the mark from combobox1
dim ds2 as new dataset
dim da2 as new Sqlclient.SqlDataAdapter(mycommand2)
'I use the same dataadapter but take another that is for me easier to
explain to you
dim cmb as new commandbuilder(da2)
da.fill(ds2)
me.combobox2.datasource = nothing
me.combobox2.datasource =ds2.tables(0)
me.combobox1.displaymember = "regist"
5) 'Submit' button to push all rows in the datatable to my database
There is a by me known bug in the combobox, otherwise I did know another
method so I have to do it something strange.
dim position as integer = CType(BindingContext(ds.Tables(0)),
CurrencyManager).position
ds2.tables(0).rows(position)("date")=registrationd ate
try
da2.update(ds2)
catch ex as exception
messagebox.show(ex)
start procedure again with combobox1
end try
Otherwise print bill.
I think this is much easier to make. Try it by first copying your project to
a new one. Do not do it in your project you now have made, you will see that
it is ready very fast. (use first normal select statements before you use
stored procedures, that you can change when all is working nice)
When you put the concurrency checkings on the right place you have it in my
opinion multi user. This is very easy to convert to a webapplication,
because you use the datasets in a single messagetraject with a webpage.
(Although you have to save the last one for a webpage to be able to do the
update)
Do not forget that you also need a routine for correction (canceled hires).
I would use for that as start a dataset from the whole car database and a
datagrid.
Do not forget the databinding.......endcurrentupdate with that last before
you do the update.
I hope you are a little bit further, sorry that it seems that I ruin a
little bit your approach but that is not true, I only try to make it more
easy, your approach stays the same.
I have all typed in in this message, so you have to check it very carefully,
my expirience with the combobox is that it can give a lot of strange
results. (Although until now I could always pass that).
I hope this helps you somehow?
Cor