|
That's because you used B as a generic type parameter but B does not exist.
If you change map to map<B> it should work (and with some luck you won't even need to make B explicit in invocations of map , if the compiler can figure out the type for you)
|
|
|
|
|
Thanks, that took care of it for me.
|
|
|
|
|
Say, I have a resource file Res.resx with strings predefined. Then I create a new form using designer. Is it possible to use the string resources from the designer view to assign the properties, like text, so the line in the designer file would look like:
this.Text = global::My.Namespace.Res.Localized_text; ?
|
|
|
|
|
I have seen most of sniffering application sniffs network traffic according to IP address or NIC cards. But I want to sniff at application level. Real example can be an Anti-virus Application. It can sniff and block requests at application level.
So how can I do something like that ? Any example or guidance ?
Or
Is there any way to find out which application sent a given request ?
|
|
|
|
|
Hi,
I am using c# and sql for this simple example and I have two related tables: Master, Details. The Primary Key in Master is MasterId and there is a Foreign Key in Details table to establish the relation. The columns of Master are bound to textbox while the Details table are bound to datagridview. MasterBindingSource and DetailBindingSource are generated automatically. My problem with this is that adding a new Master along with its Details, coz it errors with FK constraint violated. Actually, when I add a new Master, the MasterId value @ the textbox is -1, so the value that was recognized by the Details MasterId @ the datagridview is -1 likewise, so when the insertion is updated to the database, MasterId is automatically set by the db engine due to its identity property. However, this MasterId is not known to the dataset. So when the Details table is updated to the database, the error occurs(Sql Exception was unhandled). So I need help for this problem coz I tried everything but nothing happened.
Anyway, here is my simple code as shown:
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 System.Data.SqlClient;
namespace MasterDetail
{
public partial class Form1 : Form
{
//DsMasterDetail ds = new DsMasterDetail();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.masterTableAdapter.Fill(this.dsMasterDetail.Master);
this.detailTableAdapter.Fill(this.dsMasterDetail.Detail);
}
void Master_RowChanged(object sender, DataRowChangeEventArgs args)
{
}
private void masterBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
Validate();
masterBindingSource.EndEdit();
masterTableAdapter.Update(this.dsMasterDetail.Master);
dgvDetail.Refresh();
detailBindingSource.EndEdit();
detailTableAdapter.Update(this.dsMasterDetail.Detail);
}
private void dgvDetail_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
//e.Row.Cells[1].Value = bnPositionItem.Text;
}
}
}
Thanks in advance, your help will be greatly appreciated.
|
|
|
|
|
I think instead of using masterTableAdapter.Update(this.dsMasterDetail.Master);
you can use sql query to insert new data.
rahul
|
|
|
|
|
Hi Rahul,
Anyway, tnx for the reply. So I will redesign my code using a query instead of using MasterTableAdapter. I will send you feedback later if there's still a problem.
Thanks again.
|
|
|
|
|
Hi,
I think i found the best solution using this code below:
void save()
{
Validate();
// Disable constraints
ds.EnforceConstraints = false;
DsMasterDetail.MasterRow master = (DsMasterDetail.MasterRow)(((DataRowView)masterBindingSource.Current).Row);
DsMasterDetail.DetailRow detail = (DsMasterDetail.DetailRow)(((DataRowView)detailBindingSource.Current).Row);
masterBindingSource.EndEdit();
masterTableAdapter.Update(master);
detail.MasterId = master.MasterId;
detailBindingSource.EndEdit();
detailTableAdapter.Update(detail);
//Re-enable constraints
ds.EnforceConstraints = true;
}
This code solves my problem with Fk_Constraint. Actually it is working only for single data entry at details data table, but the only problem is that when adding a new Master at the textbox along with multiple details at the datagridview at the same time, coz it only fires up the last record of the datagrid and bypasses the corresponding rows. I need help for this problem.
Thanks.
Hardz
|
|
|
|
|
Redesign and don't use a Grid.
|
|
|
|
|
Hi,
Anyway, I am using a datagridview for data entry coz for every Master there's a corresponding multiple details, so the reason for using a datagridview is to enter many details.
Tnx for the reply..
|
|
|
|
|
You'll be better of designing a form or a series of forms for entering the data. And your users will probably prefer it.
|
|
|
|
|
Hi,
Tnx for the reply and suggestions that helps me a lot.
Anyway, i created a solution that solves for my problem in master/detail relationship, but not really the best one. so here is the revised code as shown below:
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 System.Data.SqlClient;
namespace MasterChild
{
public partial class Form1 : Form
{
bool addIndicator = false;
DataSet ds = new DataSet();
int lastNoOfMasterId;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.masterTableAdapter.Fill(this.dsMaster.Master);
detailLoadValue();
lastno();
}
void lastno()
{
bnMoveLastItem.PerformClick();
lastNoOfMasterId = int.Parse(txtMasterId.Text);
}
void detailLoad()
{
try
{
this.detailTableAdapter.Fill(this.dsDetail.Detail, new System.Nullable<int>(((int)(System.Convert.ChangeType(lblMasterId.Text, typeof(int))))));
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
void detailLoadValue()
{
lblMasterId.Text = txtMasterId.Text;
detailLoad();
}
private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
{
detailLoadValue();
}
private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e)
{
detailLoadValue();
}
private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)
{
detailLoadValue();
}
private void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e)
{
detailLoadValue();
}
private void masterBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
ds.EnforceConstraints = false;
this.masterBindingSource.EndEdit();
this.masterTableAdapter.Update(this.dsMaster.Master);
this.detailBindingSource.EndEdit();
this.detailTableAdapter.Update(this.dsDetail.Detail);
ds.EnforceConstraints = true;
addIndicator = false;
}
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
if (addIndicator)
{
return;
}
else
{
detailLoadValue();
lastNoOfMasterId += 1;
addIndicator = true;
}
}
private void dgvDetail_RowEnter(object sender, DataGridViewCellEventArgs e)
{
if (addIndicator)
{
lblMasterId.Text = lastNoOfMasterId.ToString();
}
else
{
lblMasterId.Text = txtMasterId.Text;
}
}
}
}
So using the integer lastNoOfMasterId that detects the last number of MasterId and automatically incremented if the user press an add button, which is now a value of MasterId at Details datagrid, replacing the -1 default value during add. With this i am not having trouble now on null value of MasterId at details table and adding a new master along with its details is no longer a problem to me.
But i think this kind of code is much more complicated. Is there any simplified one aside from this?
tnx again for the suggestions.
Har
|
|
|
|
|
Greetings !
I am new to programming, iwant your help to creat an rss reader in C# using visual studio 2010.
thaks
|
|
|
|
|
|
You have posted a similar question in the .Net framework forums as well.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Abhinav S wrote: You have posted a similar question in the .Net framework forums as well.
Perhaps he's writing two applications, one using C# and one in a different CLI language (perhaps F#) and wants to compare and contrast the differences in approach and thinking. Or maybe he's just cross posting!
|
|
|
|
|
Errrmmmmmmm I call Occam's razor
|
|
|
|
|
This[^] article may help get you started.
/ravi
|
|
|
|
|
Hi guys,
I'm using the following code to restore a backup sql database with C# and SMO.
void RestoreDatabaseWithSMO(string sConnect, string dbName, string backUpPath)
{
using (SqlConnection cnn = new SqlConnection(sConnect))
{
cnn.Open();
cnn.ChangeDatabase("master");
ServerConnection sc = new ServerConnection(cnn);
Server sv = new Server(sc);
if (!sv.Databases.Contains(dbName))
throw new Exception("this DataBase does not exist");
BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File);
Restore resDB = new Restore();
resDB.PercentComplete += new PercentCompleteEventHandler(percentComplete);
resDB.PercentCompleteNotification = 10;
resDB.Devices.Add(bdi);
resDB.NoRecovery = false;
resDB.ReplaceDatabase = true;
resDB.Database = dbName;
resDB.Action = RestoreActionType.Database;
resDB.SqlRestore(sv);
}
}
but in the last line I got below exception !!!
{"Restore failed for Server '\\\\.\\pipe\\3F103E6E-3FD4-47\\tsql\\query'. "}
What's wrong with it ?
Could you please guide me?
Thanks
|
|
|
|
|
Hello everyone
I've generated an SQL statement in my .cs file as
cmd.Connection = conn //this is working, worked before in the same code
cmd.CommandText = "INSERT INTO <table> VALUES ('value1','value2')";
conn.Open
cmd.ExecuteNonQuery
conn.Close
the problem is:
I'm checking the SQL statement in debug, copying the same query on my MySQL QueryBrowser and executing
the same string works in the querybrowser, but in ExecuteNonQuery() doesn't
what can be the problem?
notes:
1-connection is done, checked, and double checked, a few lines earlier, several SELECT statements are
executed and worked
2-connection string is not changed before this code, it was the same before
3-I'm not changing the code while copying to the Querybrowser, taking the text as it is directly from
debug window and pasting it to the SQL browser tool.
any ideas?
<div class="modified">modified on Tuesday, October 19, 2010 2:39 PM</div>
|
|
|
|
|
I don't know what you did, but all those SPANs seem to mess up the entire forum page. I would suggest you edit your existing post and refrain from using excessive HTML tags, the one you do want is the PRE tag for showing code.
|
|
|
|
|
The correct statement is:
INSERT INTO TABLE (FIELD1, FIELD2) VALUES ('value1','value2')
The data type must be the same type. For example:
if Field1 = string, Field2 = numeric then
INSERT INTO TABLE (FIELD1, FIELD2) VALUES ('value1',123)
sorry, for my language
I'm still learning
|
|
|
|
|
Thank you but,
The statement is forming correctly, I'm copying the text into query browser and executing
it's working there
|
|
|
|
|
So, show me how you create connection object and command object or take a look at this code:
'MS Access
'Execute = INSERT, UPDATE, DELETE
Public Function ExecuteDbData(ByVal oConn As System.Data.OleDb.OleDbConnection, ByVal sSQL As String) As Long
Dim oComm As System.Data.OleDb.OleDbCommand, oTrans As System.Data.OleDb.OleDbTransaction = Nothing
Dim iRetVal As Integer
Try
oConn.Open()
oTrans = oConn.BeginTransaction()
oComm = New System.Data.OleDb.OleDbCommand(sSQL, oConn, oTrans)
iRetVal = oComm.ExecuteNonQuery()
oTrans.Commit()
Catch ex As System.Data.OleDb.OleDbException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
Try
oTrans.Rollback()
oTrans.Dispose()
Catch
'do nothing
End Try
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
Finally
oConn.Close()
oTrans = Nothing
oComm = Nothing
End Try
Return iRetVal
End Function
'MS SQL
'Execute = INSERT, UPDATE, DELETE
Public Function ExecuteDbData(ByVal oConn As System.Data.SqlClient.SqlConnection, ByVal sSQL As String) As Long
Dim oComm As System.Data.SqlClient.SqlCommand, oTrans As System.Data.SqlClient.SqlTransaction = Nothing
Dim iRetVal As Integer
Try
oConn.Open()
oTrans = oConn.BeginTransaction(System.Data.IsolationLevel.Serializable)
oComm = New System.Data.SqlClient.SqlCommand(sSQL, oConn, oTrans)
iRetVal = oComm.ExecuteNonQuery()
oTrans.Commit()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
Try
oTrans.Rollback()
oTrans.Dispose()
Catch
'do nothing
End Try
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
Finally
oConn.Close()
oTrans = Nothing
oComm = Nothing
End Try
Return iRetVal
End Function
sorry, for my language
I'm still learning
|
|
|
|
|
Sorry everyone
I figured out that I was working on another dataBase with my querybrowser
I just duplicated the databases and that fooled me in the first place
I wasn't aware of the difference until 3 hours of crisis
sorry for disturbance
thanks for any help
|
|
|
|
|