Showing posts with label datagrid. Show all posts
Showing posts with label datagrid. Show all posts

Monday, March 26, 2012

MS SQL Server Date problem

hi...

i am using MS SQL 2000 as my server in my project.

but when i enter date from vb.net datagrid somtimes it shows me error of char can't be converted to date.Date Overflow problem.

it also has problem with the date modification for date which has month and date values btween

1 - 12 (i.e. like 04/11/2005 and 11/04/2005)

please help me regarding this as i have spend so much time on this but not able to get soluation

Go into the advanced options of your update statement parameters and change the datatype from "Empty" to "DateTime".

|||

how to Go into the advanced options of update statement parameters and change the datatype from "Empty" to "DateTime".

will it cause the problem when i will try to update the data which will be not of the 'datetime' type?

|||

Depends on the tool you are using I suppose. You can also just add the attribute Type="datetime" on the parameter.

And yes, it will cause a problem if you try to update the data if it's not covertable to a datetime type. For example the string "blah" will cause a problem, but the string "2/15/2006" will not cause a problem IF your current culture accepts that as a valid date format (Like en-US).

|||

A workaround for different cultural date settings that I use is to manually build the date string from the different components of the date.

For example, if I need to insert DateTime.Now into the database, I will build the following:

string dateNow = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + " " + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second + ".000";

This will build 2006-02-22 11:55:44.000 which will work everytime, no matter what culture settings the user's browser is set to.

On another note, here is a helper method to determine if a string is in a date format (doesn't help with cultural issues though):

public static bool IsDate(object dt)
{
try
{
System.DateTime.Parse(dt.ToString());
return true;
}
catch
{
return false;
}
}

Friday, March 9, 2012

MS SQL and ASP.NET connection problem

Hi,

Im trying to set up a ASP.NET webform to a MS SQL database. Im currently databinding to a datagrid. My code seems to compile correctly, no errors, however the data does not display.

I have tried to connect to the database server using the data adapter preview and works perfectly. But once i get the webpage running nothing displays from my VB code.

Does anyone have any clue to a resolution? THANK YOU ALL!I don't know if this is the problem, but I think after setting the datagrid's datasource property to the dataset, you have to type this:
"datagrid1.bind" or maybe "datagrid1.databind" (one of them: I can't quite remember)

Hope this helps.
Wes

Monday, February 20, 2012

MS SQL + ADO + VB6, Which is the best method ?

First, sorry for my english

In vb.6 I use 2 DataCombo and 1 DataGrid in 1 Form, totally I need 3 recordset on 1 form.

All 3 recordset is from MS SQL Server in one database.

Which is the best method ?

1. To place 3 ADODC control on the form and for each

ADODC1.ConnectionString="......................"
ADODC1.RecordSource="SELECT * FROM Table1"

ADODC2.ConnectionString = the same as ADODC 1
ADODC2.RecordSource="SELECT * FROM Table2"

ADODC3.ConnectionString = the same as ADODC 1
ADODC3.RecordSource="SELECT * FROM Table3"

OR

2. I don't use ADODC control, I use a single connection and 3 Recordset

Set cn = New ADODB.Connection

With cn
.ConnectionString = ".........."
.Open
End With

Dim Rec1 As New ADODB.Recordset
With Rec1
.Open "SELECT * FROM Table1, cn, adOpenStatic, adLockReadOnly
End With

Dim Rec2 As New ADODB.Recordset
...........................
Dim Rec3 As New ADODB.Recordset
..............................The single connection object with multiple recordset objects is the better choice. Also, make sure you use the SQLOLEDBXX provider in your connection string.|||Another comment - declare your objects at the top of your code so

Dim cn as adodb.connection
dim rs1 as adodb.recordset
dim rs2 as adodb.recordset ...

Then instantiate the recordset object as late as possible in your code (stay away from dim as new) and destroy the object as soons as possible:

set rs1 = new adodb.recordset
'start recordset manipulation
'end recordset manipulation
set rs1 = nothing