|
I am binding to a data grid.
The following code is a snippit of a function that searches the database.
Sql = "SELECT [fldItemId] FROM tblCost where ";
Sql += "([fldCost] BETWEEN 0 AND 100)";
conn.Open();
com = new SqlCommand(Sql, conn);
reader = com.ExecuteReader();
while (reader.Read())
_ItemIdList.Add((int)reader["fldItemId"]);
conn.Close();
}
return _itemIdList;
To call the function, I use
GridSearchResults.DataSource = SearchControl.Search(query);
GridSearchResults.DataBind();
I ran other statements that did not look in the fldCost and I got records back. (btw fldCost is sql money type)
|
|
|
|
|
Have you tried putting a breakpoint on this line
<br />
GridSearchResults.DataSource = SearchControl.Search(query);<br />
and seeing if you actually get any results, but they are just not being displayed?
Also, sql money gets mapped to a decimal in c#
ChrisB
|
|
|
|
|
OK, I found what was wrong. It seems that I was clearing my list and returning a blank list. I founf this out because I ran a count in the while(reader.Read()) loop and it said 42 when the datagrid was empty.
Thanks everyone for your help.
|
|
|
|
|
Select a.*, b.* from Customers a,(Select OrderID,Orderdate,CustomerID from Orders) b where a.CustomerID = b.CustomerID
facing a prob while modifying this one through my program.. the code seems right.. not v good with sql.. is the syntax of this query correct?
|
|
|
|
|
This syntax is not correct. It seems as though you are trying to do this:
SELECT a.*, b.OrderID, b.OrderDate, b.CustomerID
FROM Customers a
INNER JOIN Orders B
ON a.CustomerID = b.CustomerID
This returns all of the records that match the conditions in BOTH a and b. Note that it is generally not good practice to use * to retrieve columns. This is just lazy practice and should be discouraged as much as possible. Instead of doing this, retrieve the parameters explicitly.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I have written one stored procedure(SP). Just I want to check whether it is running correctly or not. How can I debug a SP in sql server 2000/ 2005? is there any diff between sql server 2000 and 2005? pls suggest me.
thanks,
chakri
|
|
|
|
|
There are many ways to do this. One way would be to print out values at appropriate points.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
In SQL Server 2000, you can right click the stored procedure and debug but for SS2005 I guess you can debug only thro Visual Studio 2005.
|
|
|
|
|
I have this error when i try to update a field from my program:
SQL:Statement too long because my table contains about 15000 records and i have 26 columns CRecorrdset::Update(); he will update all !
if i try to update 1 table with 50 records is work fine!
What can i do?
My program is CDialog ,MFC!
My table visualfox 6.0!
please someoane help me!
Bravoone
|
|
|
|
|
How long is the statement ? Perhaps you need to break it up into smaller ones.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You are probably getting a timeout because of the volume of data that you are trying to update. Try to split this into smaller batches and see if that fixes it.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
i dont write an SQL statement why it give me that error ?
Bravoone
|
|
|
|
|
This is cause with using
EXEC ("SELECT...........etc.............etc.......")
Your SQL is too long and the SQL compiler don't like it.
Blog Have I http:\\www.frankkerrigan.com
|
|
|
|
|
this is my code where the code is to long where i must do that?
void CTestDlg::OnChange1()
{
CWaitCursor wait; // Display a wait cursor
CText pTextp;
CString sAnul1,sLuna,sLuna1,sZiua1,sData,sTemp;
m_1.GetWindowText(pTextp.sText4);
sTemp.TrimLeft();
sTemp.TrimRight();
m_2.GetWindowText(pTextp.sText3);
sTemp.TrimLeft();
sTemp.TrimRight();
CRecord_test pBun;
pBun.m_strFilter="password='"+ pTextp.sText3 +"'";
pBun.m_strFilter="name='"+ pTextp.sText4 +"'";
CString sTimp = "777";
pBun.Open();
int nIndexA = pBun.m_password.Find(pTextp.sText3);
int nIndexB = pBun.m_name.Find(pTextp.sText4);
if ((nIndexA != -1) & (nIndexB != -1))
{
pBun.Edit();
pBun.m_name = sTimp;
pBun.Update();
pBun.Close();
}
what is wrong here?
}
Bravoone
|
|
|
|
|
Hello colleagues,i use a database (Access):
<br />
.................................................................<br />
void Db::Next(ADODB::_RecordsetPtr& rs){<br />
try{<br />
rs->MoveNext();<br />
}catch(_com_error e){<br />
_bstr_t bstrError(e.ErrorMessage());<br />
CString strError=(TCHAR*)bstrError;<br />
AfxMessageBox(strError);<br />
}<br />
}<br />
<br />
void Db::Last(ADODB::_RecordsetPtr& rs){<br />
try{<br />
rs->MoveLast();<br />
}catch(_com_error e){<br />
_bstr_t bstrError(e.ErrorMessage());<br />
CString strError=(TCHAR*)bstrError;<br />
AfxMessageBox(strError);<br />
}<br />
}<br />
void Db::First(ADODB::_RecordsetPtr& rs){<br />
try{<br />
rs->MoveFirst();<br />
}catch(_com_error e){<br />
_bstr_t bstrError(e.ErrorMessage());<br />
CString strError=(TCHAR*)bstrError;<br />
AfxMessageBox(strError);<br />
}<br />
}<br />
<br />
bool Db::IsEoF(ADODB::_RecordsetPtr &rs){<br />
try{<br />
return !!rs->GetEOF();<br />
}catch(_com_error e){<br />
_bstr_t bstrError(e.ErrorMessage());<br />
CString strError=(TCHAR*)bstrError;<br />
AfxMessageBox(strError);<br />
return false;<br />
}<br />
}<br />
...................................................<br />
<br />
<br />
on application of metod Last,
<br />
.....................................................................<br />
CString query( FormatString(TEXT("select * from payment_info") ));<br />
ADODB::_RecordsetPtr rs = db.Execute(query);<br />
if (!rs->EOF) {<br />
db.Last(rs);<br />
.....................................................................<br />
error IDispatch error #3108. The other metod all ok.
|
|
|
|
|
I suspect that the recordset is returned as a forward only cursor. You cannot perform a MoveLast() with forward only cursors. Try to change this to a dynamic cursor to resolve the issue.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Hey,
I'm quite new with the Java language and now i am trying to use a MySQL database to store data i want to use in the app. I found this tut (http://www.codeproject.com/useritems/MySQL_with_Java.asp) on codeproject.com. But i have one problem. When run the app i get this warning:
An error occured: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
But i already put the Connector/J.jar file in my Java SDK. Who can tell me how i can solve this.
Greetings,
NightFox
|
|
|
|
|
If this question is related to an article on code project then you should ask on the forum related to that article (at the bottom of the article page) rather than here.
|
|
|
|
|
NightFox500 wrote: I found this tut (http://www.codeproject.com/useritems/MySQL_with_Java.asp) on codeproject.com. But i have one problem. When run the app i get this warning:
An error occured: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
But i already put the Connector/J.jar file in my Java SDK. Who can tell me how i can solve this
Presumably the author of the tutorial is your best bet.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi
I want to copy records from one MS Access database to another MS Access database (the two databases have exactly the same structures and tables). I am using a C# windows application to control this. Overall I do not have any problems except in the one table. In the design view I see that the data type for one of the columns is OLE Object. I loaded the data from that table into a DataTable and checked what datatype that column has in C# and it said System.Byte[].
I did the following to see if there is data in the column (the column header is “olePoints”):
byte[] oleByte = (byte[]) row["olePoints"];<br />
foreach (byte b in oleByte)<br />
{<br />
Console.Write(b.ToString() + " ")<br />
}
It seems fine. I try to write that row to the second MS Access database with the following code:
public static void InsertRecordTest(string destDbase, DataRow sourceRow)<br />
{<br />
try<br />
{<br />
string sql = "INSERT INTO Table1 ( lId, nNumberOfPoints, olePoints )"<br />
+ " VALUES (" + (int)sourceRow["lId"] + ", " <br />
+ (short)sourceRow["nNumberOfPoints"] + ", "<br />
+ (byte[])sourceRow["olePoints"] + ");";<br />
<br />
MSAccess_DAL.ModifyData(destDbase, sql); <br />
}<br />
catch (Exception e)<br />
{<br />
throw (e);<br />
}<br />
}
But it throws an exception with the following method:
Syntax error (missing operator) in query expression ‘System.Byte[]’.
Can anybody give me some ideas?
Thanks
Kobus
|
|
|
|
|
kbalias wrote: Can anybody give me some ideas?
Don't inject values into a SQL Statement. Use parameters. Please read this[^] to defend yourself against attack - Your code is vulnerable.
|
|
|
|
|
HI
I have got some error while connecting Sql Server 2000 from ASP.NEt 2.0
i.e My ASP.NET Application and SqlServer 2000 are avaliable in diffrent machine.I remotly connecting the sql server 2000.
I am getting the following error
"System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at _Default.click_Click(Object sender, EventArgs e) in d:\WebSite2\Default.aspx.cs:line 27"
Please send me ur sugessions.
Thanks
Paul
|
|
|
|
|
nesaraja wrote: Please send me ur sugessions.
Send details. Such as your connection string, the name of the machine the instance name of the SQL Server (if there is one).
|
|
|
|
|
I have trouble with deleted row in my database program. When my program starts, I start another program too (MySQLBrowser) and from MySQLBrowser, I delete one row. After that in my Program, I refresh (re-fill) my relevant DataTable but the deleted row still exist in DataTable.
I found out a solution by clearing DataTable first, then re-fill it again. It Works.
Clearing DataTable really works. But, what if there are thousands rows?
Anywayay, here's the code:
I have a Static Class which holds the only DataSet in my program. All DataTables created are stored in that DataSet.
/*******************************************************************/
public static DataSet dsObj = new DataSet(); //the one and only DataSet in my program
public static MySqlConnection connObj = new MySqlConnection(connStr);
//method to add Table or Tables to DataSet
public static void addTblsToDsObj(String tblName)
{
String[] tblArr = tblName.Split(',');
dsObj.EnforceConstraints = false; //I remove constrain before clearing DataTable, because of ForeignKey problem
for (int i = 0; i < tblArr.Length; i++ )
{
if(dsObj.Tables.Contains(tblArr[i])){ //If DataSet has same Table, I clear that table before fill it again
dsObj.Tables[tblArr[i]].Clear();
}
}
dsObj.EnforceConstraints = true; //after needed tables are cleared, I set it to true because I want to load the primary key too.
for (int i = 0; i < tblArr.Length; i++)
{
MySqlDataAdapter daObj = new MySqlDataAdapter("SELECT * FROM " + tblArr[i], connObj);
MySqlCommandBuilder cbObj = new MySqlCommandBuilder(daObj);
daObj.MissingSchemaAction = MissingSchemaAction.AddWithKey;
daObj.Fill(dsObj, tblArr[i]);
}
}
/*******************************************************************/
Now, everytime my Form load a Table from MySQL, I call method addTblsToDsObj(String tblName).
Note that code above works fine with deleted data outside my Program environtment (because if Clear method).
I repeat my question above, what if I have thousand of rows? it means I will clear a lot of unnecessary rows right? so I guess it's not an optimal performance.
Thx for any help.
|
|
|
|