Click here to Skip to main content
15,890,186 members
Home / Discussions / Database
   

Database

 
AnswerRe: Import database from local system to server system Pin
Mycroft Holmes19-Oct-08 22:02
professionalMycroft Holmes19-Oct-08 22:02 
Questionhow to retrieve UTF-8 data from SQL Server 2005 with asp.Net 2.0 Pin
Member 462760918-Oct-08 6:49
Member 462760918-Oct-08 6:49 
AnswerRe: how to retrieve UTF-8 data from SQL Server 2005 with asp.Net 2.0 Pin
Rob Graham18-Oct-08 7:03
Rob Graham18-Oct-08 7:03 
AnswerRe: how to retrieve UTF-8 data from SQL Server 2005 with asp.Net 2.0 Pin
Wendelius18-Oct-08 7:09
mentorWendelius18-Oct-08 7:09 
AnswerRe: how to retrieve UTF-8 data from SQL Server 2005 with asp.Net 2.0 Pin
N a v a n e e t h20-Oct-08 1:50
N a v a n e e t h20-Oct-08 1:50 
QuestionODBC and SQL Pin
ffowler17-Oct-08 10:47
ffowler17-Oct-08 10:47 
AnswerRe: ODBC and SQL Pin
Mycroft Holmes17-Oct-08 23:04
professionalMycroft Holmes17-Oct-08 23:04 
QuestionData being retrived from SQL Server is incorrect with Adapter.Fill Pin
chapas17-Oct-08 7:01
chapas17-Oct-08 7:01 
Hi,
i'm having a very strange problem on my code, i'm on VS2008 with .net 3.5 and with SQLServer 2005, i have the 'correct' data tracked with the profiler tool;


SELECT x.columnName, x.columnOrdinal, x.columnTypeID, x.columnMaxLength, x.columnPrecision, x.columnScale, x.columnAllowNull, x.columnIsIdentity, x.columnFKTable, Case When y.Name Is Null Then 'No' Else 'Yes' End As columnPrimaryKey
FROM ( select sc.name columnName, sc.colid columnOrdinal, sc.xusertype columnTypeID, sc.length columnMaxLength, sc.xprec columnPrecision, sc.xscale columnScale, sc.isnullable columnAllowNull, (sc.status & 0x80)/0x80 columnIsIdentity, sor.name as columnFKTable, sc.colorder
FROM [teste].[SYS].[syscolumns] sc
INNER JOIN [teste].[SYS].[sysobjects] so ON sc.id=so.id
LEFT OUTER JOIN [teste].[SYS].[sysforeignkeys] sfk ON so.id=sfk.fkeyid AND sc.colid=sfk.fkey
LEFT OUTER JOIN [teste].[SYS].[sysobjects] sor ON sor.id=sfk.rkeyid
WHERE SO.Name='Centro' ) AS x
LEFT JOIN
( SELECT c.name, c.colid
FROM sysindexes i
INNER JOIN [teste].[SYS].[sysobjects] t ON i.id = t.id
INNER JOIN [teste].[SYS].[sysindexkeys] k ON i.indid = k.indid AND i.id = k.ID
INNER JOIN [teste].[SYS].[syscolumns] c ON c.id = t.id AND c.colid = k.colid
WHERE i.id = t.id AND i.indid BETWEEN 1 And 254 AND (i.status & 2048) = 2048 AND t.id = OBJECT_ID('Centro')) As y
ON x.columnName = y.Name
ORDER BY x.colorder

the result will have this row of data:

centroID 1 56 4 10 0 0 1 NULL Yes


the problem it's on the last column, here is a 'Yes' and on VS, while debugging right after the dataadapter.fill i get a 'No', obviously with the same query.

Here is the code i used to get the data from the DB:

public void GetColumnsForTableFromDatabase(string tabela)
{
string queryForColumns = "SELECT x.columnName, x.columnOrdinal, x.columnTypeID, x.columnMaxLength, x.columnPrecision, x.columnScale, x.columnAllowNull, x.columnIsIdentity, x.columnFKTable, Case When y.Name Is Null Then 'No' Else 'Yes' End As columnPrimaryKey \r\n";
queryForColumns += "FROM ( select sc.name columnName, sc.colid columnOrdinal, sc.xusertype columnTypeID, sc.length columnMaxLength, sc.xprec columnPrecision, sc.xscale columnScale, sc.isnullable columnAllowNull, (sc.status & 0x80)/0x80 columnIsIdentity, sor.name as columnFKTable, sc.colorder \r\n";
queryForColumns += "FROM [" + cmbBoxDatabases.Text + "].[SYS].[syscolumns] sc \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysobjects] so ON sc.id=so.id \r\n";
queryForColumns += "LEFT OUTER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysforeignkeys] sfk ON so.id=sfk.fkeyid AND sc.colid=sfk.fkey \r\n";
queryForColumns += "LEFT OUTER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysobjects] sor ON sor.id=sfk.rkeyid \r\n";
queryForColumns += "WHERE SO.Name='" + tabela + "' ) AS x \r\n";
queryForColumns += "LEFT OUTER JOIN \r\n";
queryForColumns += "( SELECT c.name, c.colid \r\n";
queryForColumns += "FROM sysindexes i \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysobjects] t ON i.id = t.id \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysindexkeys] k ON i.indid = k.indid AND i.id = k.ID \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[syscolumns] c ON c.id = t.id AND c.colid = k.colid \r\n";
queryForColumns += "WHERE i.id = t.id AND i.indid BETWEEN 1 And 254 AND (i.status & 2048) = 2048 AND t.id = OBJECT_ID('" + tabela + "')) As y \r\n";
queryForColumns += "ON x.columnName = y.Name \r\n";
queryForColumns += "ORDER BY x.colorder \r\n";

sqlConn.ConnectionString = getConnectionString();
SqlCommand sqlCom = new SqlCommand(queryForColumns, sqlConn);
SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCom.CommandText, sqlConn);

if (DS.Tables.Contains(tabela))
DS.Tables[tabela].Clear();

sqlConn.Open();
sqlDA.Fill(DS, tabela);
sqlConn.Close();
}


I'm lost here, but on my tests i got the correct result if replace:


queryForColumns += "( SELECT c.name, c.colid \r\n";
queryForColumns += "FROM sysindexes i \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysobjects] t ON i.id = t.id \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[sysindexkeys] k ON i.indid = k.indid AND i.id = k.ID \r\n";
queryForColumns += "INNER JOIN [" + cmbBoxDatabases.Text + "].[SYS].[syscolumns] c ON c.id = t.id AND c.colid = k.colid \r\n";
queryForColumns += "WHERE i.id = t.id AND i.indid BETWEEN 1 And 254 AND (i.status & 2048) = 2048 AND t.id = OBJECT_ID('" + tabela + "')) As y \r\n";


with this:

queryForColumns += " ( SELECT 'centroID' as name, 1 as columnID) As y ";


i know this is strange, but it works, it leads me to think that this has something to do with the 'LEFT JOIN'.

Thanks for the help in advance,
Chapas
AnswerRe: Data being retrived from SQL Server is incorrect with Adapter.Fill Pin
Mycroft Holmes17-Oct-08 23:01
professionalMycroft Holmes17-Oct-08 23:01 
GeneralRe: Data being retrived from SQL Server is incorrect with Adapter.Fill Pin
chapas18-Oct-08 0:47
chapas18-Oct-08 0:47 
AnswerRe: Data being retrived from SQL Server is incorrect with Adapter.Fill Pin
Rob Graham18-Oct-08 7:13
Rob Graham18-Oct-08 7:13 
GeneralRe: Data being retrived from SQL Server is incorrect with Adapter.Fill Pin
Mycroft Holmes18-Oct-08 17:38
professionalMycroft Holmes18-Oct-08 17:38 
GeneralRe: Data being retrived from SQL Server is incorrect with Adapter.Fill Pin
chapas21-Oct-08 6:13
chapas21-Oct-08 6:13 
QuestionSql Pin
maana_203017-Oct-08 5:57
maana_203017-Oct-08 5:57 
AnswerSample Table create scripts Pin
David Mujica17-Oct-08 6:37
David Mujica17-Oct-08 6:37 
AnswerRe: Sql Pin
Paul Conrad17-Oct-08 6:38
professionalPaul Conrad17-Oct-08 6:38 
AnswerRe: Sql Pin
Wendelius19-Oct-08 0:12
mentorWendelius19-Oct-08 0:12 
QuestionSET NOCOUNT ON; Pin
geekfromindia17-Oct-08 5:09
geekfromindia17-Oct-08 5:09 
AnswerRe: SET NOCOUNT ON; Pin
Jon_Boy17-Oct-08 10:19
Jon_Boy17-Oct-08 10:19 
GeneralRe: SET NOCOUNT ON; Pin
geekfromindia17-Oct-08 12:01
geekfromindia17-Oct-08 12:01 
GeneralRe: SET NOCOUNT ON; Pin
Jon_Boy17-Oct-08 13:23
Jon_Boy17-Oct-08 13:23 
AnswerRe: SET NOCOUNT ON; Pin
Mycroft Holmes17-Oct-08 22:57
professionalMycroft Holmes17-Oct-08 22:57 
QuestionProblem with creating a table using a stored procedure [modified] Pin
TheComputerMan17-Oct-08 4:29
TheComputerMan17-Oct-08 4:29 
AnswerRe: Problem with creating a table using a stored procedure Pin
TheComputerMan17-Oct-08 5:22
TheComputerMan17-Oct-08 5:22 
AnswerRe: Problem with creating a table using a stored procedure Pin
Kevin Horgan23-Oct-08 2:08
Kevin Horgan23-Oct-08 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.