Anyone who is working in programming.

Salam. Is there anyone, who is a programmer in any language (specifically in vb.net), but i repeat anyone programming language, in which DataBase is using at the backEnd. Please reply.

Re: Anyone who is working in programming.

Not sure if I got the question right but if you are asking which DB to use when programming in VB.Net then it is SQLServer or MS Access. If you can specify some details, I am sure a lot of people here will be able to offer their expert advice. My team works in PHP and we use MySQL.

Re: Anyone who is working in programming.

I work with Vb .net / SQL server / Oracle 9i and 11G. please specify details.

Re: Anyone who is working in programming.

First. Its so exciting that someone is here for working in vb.net and sql server.

I'm not so professional to vb.net and sql server (both 2005), so i might have so many mistakes in my programming. Please guide me

Here is my problem:

I've a form with a textbox, button and a DataGridView, right. When the forms loading so the last inserted record is binding with textbox with following code:


dsSql2.Clear()

        Dim selSale As String = "select top 1 Sale_Date from SaleInfo order by Sale_ID Desc"
        Dim cmdSql As New SqlCommand(selSale, cnSql)
        cmdSql.CommandType = CommandType.Text
        daSql.SelectCommand = cmdSql
        daSql.Fill(dsSql2, "SaleInfo")

        TextBox1.DataBindings.Add("text", dsSql2, "SaleInfo.Sale_Date")


and when i press the button so what i want that all the related records, matched with the criteria of textobx, needs to be displayed in DGV. In my case, there are 4 records in the last insertion attempt, so it means that all 4 records must be displayed in DataGridView (DGV). I have the following code on click button.


 cnSql.Open()
        Dim sel As String = "select * from SaleInfo where Sale_Date = '" & TextBox1.Text & "'"

        Dim cmdSql As New SqlCommand(sel, cnSql)
        cmdSql.CommandType = CommandType.Text
        daSql.SelectCommand = cmdSql
        daSql.Fill(dsSql2, "SaleInfo")

        DataGridView1.DataSource = dsSql2
        DataGridView1.DataMember = "SaleInfo"

cnSql.close


When i press the button, so it only displays one record in DGV. Why? what is wrong with this code? Please guide me.

Re: Anyone who is working in programming.

I haven't done vb.net but just a question here....you are selecting from a database using a date. Are you sure you want an equal to "=" there? Do all of the 4 records have the same date stamp? Even down to the millisecond?

You probably will need to run the query in a SQL Server Management Studio and see what kind of records you get if you run a query with the same imput as above.

Re: Anyone who is working in programming.

^ as Joel said, the problem is with the SQL query not with the program logic, run the query on Query Analyzer or directly on the Management Studio and check the result there, if it gives you the same result as your program output, then you need to broaden your query to include more data.

Re: Anyone who is working in programming.

First thing first , stop living in stone age and start using Entity Framework . It will make your life a lot easier and will prevent any SQL injection attack . Guys start using ORM if you haven't done that yet .

Second thing , start using LINQ so you won't have to worry about ''syntax'' of your SQL query . Rather you'll know it if its right or wrong at compile time .

Using both of the above techniques your solution should be two linear .

mydatagrid.datasource = entitymanager.SalesInfo.where( o => o.Sales_Date == DateTime.Parse(Textbox.text));
mydatagrid.databind();

Good luck learning new technologies and welcome to 2013 :)

Re: Anyone who is working in programming.

^^ Linq is the way forward... simplifies code massively :)

Re: Anyone who is working in programming.

Going off topic here but I dont know if any of you here have heard of Django (not the movie). Here is a little about it from the wikipedia. Works about the same as the code above.

Django is a free and open source web application framework, written in Python, which follows the model–view–controller architectural pattern.

Django's primary goal is to ease the creation of complex, database-driven websites. Django emphasizes reusability and "pluggability" of components, rapid development, and the principle of don't repeat yourself. Python is used throughout, even for settings, files, and data models. Django also provides an optional administrative create, read, update and delete interface that is generated dynamically through introspection and configured via admin models.

Re: Anyone who is working in programming.

@ JoelKhan & @ Rayan.

[QUOTE]
you are selecting from a database using a date. Are you sure you want an equal to "=" there? Do all of the 4 records have the same date stamp? Even down to the millisecond?

You probably will need to run the query in a SQL Server Management Studio and see what kind of records you get if you run a query with the same imput as above.
[/QUOTE]

and

[QUOTE]
run the query on Query Analyzer or directly on the Management Studio and check the result there, if it gives you the same result as your program output, then you need to broaden your query to include more data.
[/QUOTE]

What you mean by broaden your query?

Yes Joel, = is must. And i have run the query in Management Studio, it gives me result, exactly what i needed. No problem with query.

Re: Anyone who is working in programming.

Can you please post your query from management studio?

Re: Anyone who is working in programming.

well there is apparently nothing wrong with the SQL statement. look at what the string is returning once the text from the textbox is concatenated.. try using stringbuilder instead... or even better, use linq :)

Re: Anyone who is working in programming.

I've worked on the it, last night. So i came up with this situation. My new query is:


Dim selSale As String = "SELECT * FROM SaleInfo WHERE Sale_Date = (SELECT Top 1 Sale_Date FROM SaleInfo ORDER BY Sale_Date DESC)"
        Dim cmdSql As New SqlCommand(selSale, cnSql)
        cmdSql.CommandType = CommandType.Text
        daSql.SelectCommand = cmdSql
        daSql.Fill(dsSql2, "SaleInfo")
        DateTimePicker1.DataBindings.Add("text", dsSql2, "SaleInfo.Sale_Date") 

I think this is working perfectly for me. But i want your opines on it.

Re: Anyone who is working in programming.

this query working absolutely fine in SqL too.

Re: Anyone who is working in programming.

Your datetime value will only match if it will match to the last minute of last second i.e. ‘4/2/2013’ won’t match ‘4/2/2013 12:12:12’, because by default when you pass in the value ‘4/2/2013’ then it means ‘4/2/2013 00:00:00’. So try to match the range instead of exact value .

Re: Anyone who is working in programming.

Hi. Do you mean that when i will insert the data at the time of 12:00am that is 00:00:00. So this will be problematic for me? Did i get your working rightly? Please guide me.

Re: Anyone who is working in programming.

Well its a data parsing issue . When you parse string ‘4/2/2013’ in to a DateTime object then this object defaults the time to midnight . Which means ‘4/2/2013 00:00:00’ . Now if the database is storing the Date as ‘4/2/2013 07:07:00’ then it won’t be equal to the date that you want . If you are not sure about the date that you are storing in the database then always use range . i.e. is my date is between ‘4/2/2013’ and ‘5/2/2013’.

Re: Anyone who is working in programming.

Thats what I have been trying to point out in the query. The date/time match is always tricky since you have to match the time down to the milliseconds so you would have to give it a range. That was one of the reasons I wanted to see the query. Also, if you could post the results from the query in management studio that would tell us the dates that you are working with. Dont have to post anything else. Just dates from the query result set.

Re: Anyone who is working in programming.

As in my application, I’m showing the result both in DGV and Crystal Report as well, so in DGV Sale_Date =
[TABLE]


**4/1/2013 8:42 PM**

and in Crystal Report it appears like this:


**4/1/2013 8:42:47 PM**

and in DataBase its like this in the Table:


 **4/1/2013 8:42:47 PM** 

.