|
Why you have deleted your post?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
modified on Friday, July 24, 2009 2:57 PM
|
|
|
|
|
lol...because it wasn't relevant to the initial question.
|
|
|
|
|
Hi All,
I still haven't been able to SAConnection working correctly. I'm currently receiving the error:
"Invalid connection string. Error parsing connection parameter string
Parameter name: connectionString"
on the following line of code:
SAConnection oConn = new SAConnection(ConnString);
The connection string I'm using is of the following format:
string ConnString = "Data source=ServerName;Initial catalog=DBName;UID=UserID;PWD=Password";
Could you give me some pointers on what I should be entering for the 'Data Source' is this just the server name or the server name plus the path to the database etc? i've tried both with no luck but if I can pin point what is required then I have a better chance of getting it to work.
Hope you can help,
Mel
|
|
|
|
|
First of all when I select multiple rows to delete then it gives me an error:
"Uncomitted new rows cannot be deleted."
Secondly, if I select only one row at a time and click the delete button then it deletes all the rows from the database table.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using Dotnet67.Sales.DAL;
using Dotnet67.Sales.Items;
using Dotnet67.Sales.Persons;
using System.Data.SqlClient;
namespace Dotnet67.Sales.DAL
{
public class DALHelper
{
private readonly string CONSTRING3 = "CASHIER1";
private readonly string CONSTRING5 = "DELETE1";
// THE FOLLOWING IS THE CODE WHERE I GET ERRORS
public void DeleteUser(int id)
{
SqlTransaction tran = con.BeginTransaction();
SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");
SqlCommand com = new SqlCommand(CONSTRING5, con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@CashierID", id);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
public void InsertIntoCashier(string[] str,int[] val)
{
SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");
SqlCommand com = new SqlCommand(this.CONSTRING3, con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@CashierID", val[0]);
com.Parameters.AddWithValue("@CashierName", str[0]);
con.Open();
try
{
com.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dotnet67.Sales.DAL;
using Dotnet67.CommonTypes;
using Dotnet67.WinControls;
using System.Data.Sql;
using System.Data.SqlClient;
namespace Dotnet67.Sales.WinUI
{
public partial class ManageCashier : Form
{
public ManageCashier()
{
InitializeComponent();
}
private readonly string CONSTRING5 = "DELETE1";
private void ManageCashier_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dotnet67DataSet8.Cashier_2' table. You can move, or remove it, as needed.
this.cashier_2TableAdapter.Fill(this.dotnet67DataSet8.Cashier_2);
}
//This is the button for inserting values into grid view which is running perfect.
private void btnDB_Click(object sender, EventArgs e)
{
DALHelper dH = new DALHelper();
string[] str = new string[3];
int[] values = new int[3];
str[0] = txtName.Text;
dH.InsertIntoCashier(str, values);
dataGridView1.Refresh();
dataGridView1.RefreshEdit();
this.cashier_2TableAdapter.Fill(this.dotnet67DataSet8.Cashier_2);
}
// THIS IS THE DELETE BUTTON ON MY FORM WHERE I AM GETTING PROBLEM
private void btnDELETE_Click(object sender, EventArgs e)
{
DALHelper dH = new DALHelper();
List<int> rowsToDelete = new List<int>();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToBoolean(dataGridView1["column1", i].Value))
{
rowsToDelete.Add(i);
}
foreach (int rowIndex in rowsToDelete)
{
dataGridView1.Rows.RemoveAt(rowIndex);
}
dH.DeleteUser(i);
}
}
}
}
[\code]
|
|
|
|
|
Omar Akhtar Sheikh wrote: First of all when I select multiple rows to delete then it gives me an error:
"Uncomitted new rows cannot be deleted."
It is becuase, you are trying to delete one row which is in Edit mode and not comitted with DB.
Omar Akhtar Sheikh wrote: dataGridView1.Rows.RemoveAt(rowIndex);
You just try to implement this.
if (!dataGridView1.Rows[i].IsNewRow)
Note : Please make sure, while post code , please post it with proper format. Otherwise it really make difficult to read and understand.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
You have
SqlTransaction tran = con.BeginTransaction();
but no commit statement.... that may not be exactly the reason why your code fails but it is odd that you have BeginTransaction without CommitTransaction or Rollback.
Secondly, after doing edits to the datagrid, unless you save changes to database, you can't delete them from the database. You can only remove them from the data grid
|
|
|
|
|
I am trying to get the keystrokes as a user types but when my program loses focus (example is when minimized), i can no longer get the keys pressed. Any idea on how i can solve that problem?
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
|
|
how i can create query wizard to database
|
|
|
|
|
mohammad alnoed wrote: how i can create query wizard to database
What does it mean ? You want to create a similiar application like query wizerd ?
or you want know how to used it?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
yes I am working to create application I know how create connection by wizard but I don't know how create query wizard to database to get one vlaue
note
in the database three colume
id
name
level
on form I use datagridview have same columen likes database .
I need if I was inserting number 1 in colume id in datagridview other column get data from database
after this explean I just want to know how create query wizare to get on value like
select name from student where id=1;
|
|
|
|
|
mohammad alnoed wrote: yes I am working to create application I know how create connection by wizard but I don't know how create query wizard to database to get one vlaue
I am really confused with your question. What do you mean by that ? You want to show data in your datagrid?
Please state your problem clearly.
You have asked the same question over Here , and think you are not able to express what you wants .
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello,
Do you guys know any open source C# implementation of XAML Object Mapping Specification? If yes, please share me some links.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
Hi Michael,
Personally I do not know !
But, we have a "grandmaster" of XAML here on CodeProject, Marc Clifton, and I suggest you take a look at his many articles :
http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=36803[^]
And then there is Josh Smith, and Sacha Barber, WPF Gurus, they also have written on XAML, I believe.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Thanks, Bill.
I emailed to Marc (Marc Clifton) regarding his MyXaml implementation last night and got his reply saying that this specification wasn't out yet when he was implementating MyXaml and he doesn't have any implementation for that specification as well..
but yes. I will broadcast the mail in WPF-Discipline group since Josh, Sacha and others are in that group..
Thanks, man.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
I'm trying to make a column of a datagridview to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have:
1) Initially all the cells of the dtp column should be blank unless they are filled by the user.
2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control and it is checked, else the dtp editing control remains unchecked.
3) If the user selects a date from the dtp editing control and moves to another cell the value of the dtp should be set to the previous cell in string format (In that way we can define custom format for the cell e.g. dd MMM yyyy).
4) If the user unchecks the dtp editing control while it's on a cell the value of that cell should be set to null irrespective of whether the cell had a value beforehand.
I managed everything till point 3. But can't work out with point 4. Cannot set the value of a cell to null when its dtp editing control is unchecked. There's a way to do it by handling the Datagridview_CellValidating event. But in that case if the datagridview is data bound, u need to uncheck the editing control once, goto another cell, come back to the previous one and uncheck it once again to set its cell value to null. I want to know if there's any way to do it through the derived classes or their class template that I'm using so that I wont have to use that event and everything can be done through the class template only. Please help. My code follows:
Code for the template (I'm using a code file) containing all the derived classes:
using System;
using System.Windows.Forms;
namespace DGV_DateTimePicker
{
public class DateTimePickerColumn : DataGridViewColumn
{
public DateTimePickerColumn()
: base(new DateTimePickerCell())
{
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(DateTimePickerCell)))
{
throw new InvalidCastException("Must be a DateTimePickerCell");
}
base.CellTemplate = value;
}
}
}
public class DateTimePickerCell : DataGridViewTextBoxCell
{
public DateTimePickerCell()
: base()
{
this.Style.Format = "dd MMM yyyy";
}
public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue,
dataGridViewCellStyle);
DateTimePickerEditingControl ctl = (DateTimePickerEditingControl)DataGridView.EditingControl;
DateTime d;
ctl.Value = DateTime.TryParse((Value ?? "").ToString(), out d) ? d : DateTime.Now;
if (ctl.EditingControlDataGridView.CurrentCell.OwningColumn.IsDataBound)
ctl.Checked = Value.ToString() == "" ? false : Value == null ? false : true;
else
ctl.Checked = Value == null ? false : true;
}
public override Type EditType
{
get
{
return typeof(DateTimePickerEditingControl);
}
}
public override Type ValueType
{
get
{
return typeof(DateTime);
}
}
public override object DefaultNewRowValue
{
get
{
return null;
}
}
}
class DateTimePickerEditingControl : DateTimePicker, IDataGridViewEditingControl
{
DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;
public DateTimePickerEditingControl()
{
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = "dd MMM yyyy";
this.ShowCheckBox = true;
this.Checked = false;
}
public object EditingControlFormattedValue
{
get
{
return this.Value.ToShortDateString();
}
set
{
if (value is String)
{
this.Value = DateTime.Parse((String)value);
}
}
}
public object GetEditingControlFormattedValue(
DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}
public void ApplyCellStyleToEditingControl(
DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.CalendarForeColor = dataGridViewCellStyle.ForeColor;
this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;
}
public int EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
rowIndex = value;
}
}
public bool EditingControlWantsInputKey(
Keys key, bool dataGridViewWantsInputKey)
{
switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return !dataGridViewWantsInputKey;
}
}
public void PrepareEditingControlForEdit(bool selectAll)
{
}
public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}
public DataGridView EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}
public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}
public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}
protected override void OnValueChanged(EventArgs eventargs)
{
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(eventargs);
}
}
}
Code for the form containing the datagridview:
private void Form1_Load(object sender, EventArgs e)
{
DateTimePickerColumn col = new DateTimePickerColumn();
dataGridView1.Columns.Add(col);
dataGridView1.RowCount = 5;
}
Reference from MSDN 2005- How to: Host Controls in Windows Forms DataGridView Cells
|
|
|
|
|
|
If u check my post, at the footer I have already mentioned about the link u referred. I took reference from that topic but still it doesn't fulfill certain requirements that I mentioned in my points.
|
|
|
|
|
Hi
I have a webBrowser control in my Windows form and I show a logo in that webBrowser (don't ask why ). When a the logo inside webBrowser he can drag it into anywhere. But I want this webBrowser to function just like a picturebox. How can I make the webBrowser to seem like functioning just like a picturebox?
Thanks.
|
|
|
|
|
Not sure how you could do that, but perhaps instead you could download the image from the website and then just load that into an actual picture box
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I know you're saying "don't ask why", but this post begs the question "Why?" What additional functionality are you getting by doing it this way instead of using a pictureBox? I'm just curious.
|
|
|
|
|
Because I may need to run flash files there in future.
|
|
|
|
|
Well, you can always structure the HTML displayed in the webBrowser so that it doesn't link to anything.
You could also try setting the Enabled property to False .
|
|
|
|
|
WebBrowser control doesn't contain an Enabled property.
|
|
|
|