|
This is nothing to do with C#; please post to the Test forum.
|
|
|
|
|
Usually you don't write unit tests for DAL. You should write tests for business layer. If it involves calls to DAL, it should be mocked. IMO, writing unit tests after completing the project is very tough. Your classes might not be test friendly and refactoring will be a pain.
|
|
|
|
|
Hi, I am trying to connect to Sybase SQLAnyWhere DB from C# using ODBC Data Connection.
I am getting the below error.
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Can anyone tell me the reason for that ?
Error Report :
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Data.Common.UnsafeNativeMethods.SQLExecDirectW(OdbcStatementHandle StatementHandle, String StatementText, Int32 TextLength)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Odbc.OdbcCommand.ExecuteReader()
I have a list of command strings.
I am exceuting the following commands in for loop.
foreach (string str in stringlist)
{
OdbcCommand defineTankCMD = Conn.CreateCommand();
defineTankCMD.CommandText = str;
OdbcDataReader defineTankReader = defineTankCMD.ExecuteReader();
defineTankReader.Close();
}
Is it OK. some times it is working fine and some times it was giving error.
|
|
|
|
|
I would like to know how can I get access to the Non-Public members of a class. In this case it is the
CellPaintinEventArgs of a DataGridView control that I would like to be able to access outside of the CellPainting event.
I know it's not common practice or even if it's possible, but I would like to call the CellPainting event directly and pass in the DataGrid and CellPaintingEventArgs myself.
Reason being is I am trying to improve the performance (efficiency) of the CellPainting event for the DataGridView control. From a little experimentation, I have discovered that the CellPainting event fires for cells that do not require updating. I am using DataGrids that can take up the entire display of a 19" Wide display and sometimes only a few cells need updating yet depending on the location of those cells, many more cells appear to be repainted unnecessarily. This noticeably slows the updating of the grid. The data is not bound to the grid and no rows or columns are added or removed from the grid. In other words the grid size remains static so there is nothing extreme happening that would force the grid to repaint most of its cells.
The code below illustrates this. Use the default names for the components on the form. Also stretch out the grid so there's no need to scroll. Just click on different cells to change the current selected cell and you will notice that the counter reveals how many times the CellPainting event is fired for something as trivial as this! Click on the first cell and then click on the last cell, the counter increments as many times as there are cells on the grid!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace dgvTester
{
public partial class Form1 : Form
{
private int counter = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.RowCount = 10;
dataGridView1.ColumnCount = 10;
for (int column = 0; column < dataGridView1.ColumnCount; column++)
dataGridView1.Columns[column].Width = 50;
dataGridView1.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.dataGridView1_CellPainting);
}
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
counter++;
label1.Text = counter.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
counter = 0;
label1.Text = counter.ToString();
}
}
}
Do I have to override the accessibility of the CellPaintingEventArgs to be able to do this?
I found this link, don't know if it will help or how to use it:
http://www.koders.com/csharp/fid1DBCB1E079D023FE239DE7F27C34FAC67DA643AF.aspx?s=cdef%3Adatagridview#L34
Any help is much appreciated!
john....
modified on Wednesday, September 23, 2009 2:22 AM
|
|
|
|
|
I want to develop a Skinnable ToDoManager, so that I can develop different skins later and can switch from one to another during runtime (Similar to Windows Media Player http://www.microsoft.com/windows/windowsmedia/player/skins.aspx[^] ).
Can any body suggest me how to do that. I am clear in the Logic part. UI is the problem. It will be more helpful if you could provide sample codes. (I am not meaning to change the colors dynamically, instead change the appearance of controls and their positions dynamically)
|
|
|
|
|
Use WPF? You can create various xaml style sheets for the skins you want to use.
See this Codeproject article:
WPF Themes and Skins Engine[^]
|
|
|
|
|
Thank you for your quick reply. I checked the link. I already tried WPF and created a sample application that can load themes.
The problem is time taken to load the themes in WPF is high. Also I dont know how to change the complete layout (Not just color, shape of a control) runtime.
So I am trying a solution in C# instead of moving to C#. Can u suggest some solutions?
|
|
|
|
|
|
|
Do accomplish this without using WPF, you are going to have to override the controls OnPaint method of the controls etc. Can become a bit messy...
|
|
|
|
|
Please can anyone help with:-
1 How to structure the strSelect statement.
2 How to instruct the cn, da, cb, tb etc to go and get on with it.
private void btnSaveAllChangesMadeToAllLogsSoFar_Click(object sender, EventArgs e)
{
string strSelect = "UPDATE INTO dbo.tblQLs WHERE colErrByUserID = '" +
LoginForm.gb_strUserID + "' ";
SqlConnection cn = new SqlConnection(LoginForm.gb_strConnection);
SqlDataAdapter daTblQLs = new SqlDataAdapter(strSelect, LoginForm.gb_strConnection);
SqlCommandBuilder cb = new SqlCommandBuilder(daTblQLs);
cb.GetUpdateCommand();
daTblQLs.Update(gl_Dataset.ds, "tblQLs");
cn.Close();
}
Thank you for your help.
Mark
|
|
|
|
|
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Mark-123456789 wrote: SqlConnection cn = new SqlConnection(LoginForm.gb_strConnection);
So you created your connection. Now you have to establish your connection so that the database is open.
(that was a hint) try cn. and see what pops up. Maybe related to your cn.Close() command.
Mark-123456789 wrote: cb.GetUpdateCommand();
think things through: You created an update command with your strSelect. You created something that consumes that string (whether it is correct or not) and you now are calling GetUpdateCommand(). Why did you do this? Your sql was your update command. You also do not need the data adapter.
So if you use Google then you will do several searches as follows:
"SQL Server UPDATE command"
"Updating SQL Server using C#"
So what you need to do really is this:
1) create a valid Update SQL command {UPDATE tbl ... values()}
2) create and active your connection
3) Create a command using your connection and sql statement
4) Execute the command
Your SQL statement (that needs to be Executed) is considered to be NonScalar as a hint of what to do to your command.
|
|
|
|
|
Thanks for that, I have tried to use this info give and now have this...
Which is giving me a "The variable name '@colNotes' has already been declared. Variable names must be unique within a query batch or stored procedure." ERROR.
And still is not updating my Database. Also The changes i want are in a Dataset, with this new code how does it know what the changes are as there is no referance to gl_dataset.
private void btnSaveAllChangesMadeToAllLogsSoFar_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(LoginForm.gb_strConnection);
cn.Open();
string strCmdTxt = "UPDATE tblQLs SET colNotes = @colNotes " +
"WHERE [colErrByUserID] = '1'"; //" + LoginForm.gb_strUserID + "' ";
SqlDataAdapter da = new SqlDataAdapter(strCmdTxt, cn);
SqlCommand sqlCmd = new SqlCommand(strCmdTxt, cn);
sqlCmd.Parameters.Add("@colNotes", SqlDbType.NChar, 500, "colNotes");
SqlParameter parm = new SqlParameter();
parm = sqlCmd.Parameters.Add("@colNotes", SqlDbType.NChar, 500, "colNotes");
parm.SourceVersion = DataRowVersion.Original;
sqlCmd.ExecuteNonQuery();
cn.Close();
}
|
|
|
|
|
Looking better.
You still don't need the DataAdapter.
"The variable name '@colNotes' has already been declared" -- You're adding the parameter twice; don't. What do you intend to do with the parm variable anyway?
|
|
|
|
|
Thank you you help, below is the working code.
I am sure there will be smart ways to do this, but I am just happy to get it working.
The next problem (just incase you can help) is, is in another bit of code I use Textbox.text instead of the dr[col..], however the string is too long for the field and i get an error. even when i use substring(0,10). How can I auto sence the max field width and truncate it.
also (as i have you here) i would like to apply some formating to a cell on a DataViewGrid ie date dd/mm/yyyy.
private void btnSaveAllChangesMadeToAllLogsSoFar_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(LoginForm.gb_strConnection);
cn.Open();
DataTable dt = new DataTable();
dt = gl_Dataset.ds.Tables["tblQls"];
string strCommand = "";
foreach (DataRow dr in dt.Rows)
{
strCommand = "UPDATE tblQLs SET " +
"colClosedDate = '" + dr["colClosedDate"].ToString() + "', " +
"colAppealReason = '" + dr["colAppealReason"].ToString() + "', " +
"colAppealUpheld = '" + dr["colAppealUpheld"].ToString() + "', " +
"colFinalActionTaken = '" + dr["colFinalActionTaken"].ToString() + "', " +
"colNotes = '" + dr["colNotes"].ToString() + "' " +
"WHERE [colErrByUserID] = '" + dr["colErrByUserID"].ToString() + "' " +
"AND [colQLID] = '" + dr["colQLID"].ToString() + "' ";
SqlCommand cmd = new SqlCommand(strCommand);
cmd.Connection = cn;
cmd.ExecuteNonQuery();
}
cn.Close();
}
|
|
|
|
|
PLEASE use a parameterized query:
SqlCommand cmd = cn.CreateCommand ( "UPDATE tblQLs SET colClosedDate=@colClosedDate ... " ) ;
(Create and add parameters...) (It shouldn't require ToString())
foreach ( ... )
{
(Set parameter values...)
cmd.ExecuteNonQuery() ;
}
Mark-123456789 wrote: too long for the field and i get an error
I'd have to see it.
Mark-123456789 wrote: How can I auto sence the max field width and truncate it.
You'd have to access the schema, which isn't very difficult.
Mark-123456789 wrote: DataViewGrid ie date dd/mm/yyyy
I don't use DataViewGrids so I don't know off hand.
|
|
|
|
|
You wish is my command.
{
SqlConnection cn = new SqlConnection(LoginForm.gb_strConnection);
cn.Open();
// this bit is me trying a work-around-----------------------------
char[] test = new char[15];
txbColPolicyRef.Text = txbColPolicyRef.Text.Trim().ToUpper();
int intLen = txbColPolicyRef.Text.Length;
if (intLen > 15) intLen = 15;
test = txbColPolicyRef.Text.Trim().ToUpper().Substring(0, intLen ).ToCharArray();
// ------------------------------------------------------------
string strCommand = "INSERT INTO tblQLs (colQLID, colCreatedDate, colClosedDate, colErrDate, " +
"colPolicyRef, colCreatedByUserID, colErrDescription, colErrByUserID, " +
"colAppealReason, colAppealUpheld, colFinalActionTaken, colNotes, colUserTeam) " +
"VALUES (" +
"'16', " +
"'x', " +
"'" + test + "', " +
"'" + @txbColCreatedByUserID.Text.Trim().ToUpper() + "', " +
"'" + @cbColErrDescription.Text.Trim().ToUpper() + "', " +
"'" + @txbColErrByUserID.Text.Trim().ToUpper() + "', " +
"'x'," +
"'" + @txbColErrDate.Text.Trim() + "', " +
"'x','x','x','x', " +
"'" + @txbColUserTeam.Text.Trim().ToUpper() + "') ";
SqlCommand cmd = new SqlCommand(strCommand);
cmd.Connection = cn;
cmd.ExecuteNonQuery();
cn.Close();
}
|
|
|
|
|
Maybe check this[^] out.
Particularly my rendition of ExecuteNonQuery and ListColumns.
|
|
|
|
|
My friends i need help about this issue can anyone help me
|
|
|
|
|
You can use Char.IsDigit to see if a character is a digit or other character.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
thanks for your help problem solved
|
|
|
|
|
Hi,
you can use the TryParse() method of int, uint, long, ulong depending on the range you want to support; and some overloads will let you choose options, e.g. allowing thousand separators.
Warning: TryParse() will always fail on an empty TextBox.
similar for reals (float, double), dates, etc.
everything in a TextBox is a string.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
thanks alot problem solved
|
|
|
|
|
|