trantt Posted August 11, 2003 Posted August 11, 2003 I need to get a column length from either dataset, datasource, or a row object. What is the syntax for it? Here is the old syntax (ASP): recSet.Fields(iColumnIndex).DefinedSize Thank you Quote
Moderators Robby Posted August 11, 2003 Moderators Posted August 11, 2003 Do you want the column count (or size) or the row count? Quote Visit...Bassic Software
Drstein99 Posted October 7, 2003 Posted October 7, 2003 This is an old post I dont see any answer and I have the same problem does anybody have a clue? because esDataTable.Columns(0).MaxLength returns -1 for some reason. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* Volte Posted October 7, 2003 *Experts* Posted October 7, 2003 Is the first column a text field? MaxLength only returns the max lenth of text fields, and won't return the max value of number fields. Quote
Drstein99 Posted October 7, 2003 Posted October 7, 2003 Yes. I'm working with text fields. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
trantt Posted October 8, 2003 Author Posted October 8, 2003 You need to get the table schema first before you can be able to get the column length: 1. Create your connection 2. Create you Command object(Your SQL-> this will contain the table that you go after), connection) 3. Create your OleDbDataAdapter (or SQLDataAdapter) 4. Create your DataSet 5. Your dataAdapter.FillSchema(Your Data Set, System.Data.SchemaType.Mapped); Once you make the FillSchema call, your Maxlength shouldn't return -1 anymore. Hope this will help... Quote
Drstein99 Posted October 8, 2003 Posted October 8, 2003 Here is my code: Public Function SelectRows(ByVal query As String) As DataTable Dim conn As New Data.Odbc.OdbcConnection(dbConnS) Dim adapter As New Data.Odbc.OdbcDataAdapter Dim tDataSet As New DataSet Dim tDataTable As New DataTable SelectRows = Nothing adapter.SelectCommand = New Data.Odbc.OdbcCommand(query, conn) adapter.Fill(tDataSet, System.Data.SchemaType.Mapped) tDataTable = tDataSet.Tables(0) Dim etest As Integer For etest = 0 To tDataTable.Columns.Count - 1 MsgBox(tDataTable.Columns(etest).MaxLength.ToString, , tDataTable.Columns(etest).ToString) Next SelectRows = tDataTable conn.Dispose() adapter.Dispose() tDataSet.Dispose() It returns -1 as maxlen for every field. I added "System.Data.SchemaType.Mapped" to the fill command and still no avail. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Drstein99 Posted October 8, 2003 Posted October 8, 2003 I also used: adapter.fill(tdataset,"employee") (where "employee") would be the source table for mapping. Still returns -1 on every field. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Drstein99 Posted October 8, 2003 Posted October 8, 2003 I've done a little research, looks like I may have to get into useing the FillSchema command. Although it's returning system errors. If any1 has any input pls help/ Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Drstein99 Posted October 8, 2003 Posted October 8, 2003 Nevermind guys. I fixed the problem: Note to self: DO NOT have msaccess open in write mode on the table your trying to select information from another application. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.