|
|
|
i want to add new column in my database table like unique id (primary key ) when import excel file to a table then automatic generate new add column to a table (unique id ) following code:-
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string path = string.Concat((Server.MapPath("~/Data/" + FileUpload1.FileName)));
FileUpload1.PostedFile.SaveAs(path);
OleDbConnection OleDbcon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet3$]", OleDbcon);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(cmd);
OleDbcon.Open();
DbDataReader dr = cmd.ExecuteReader();
string con_str = @"Data Source=vaio\sqlexpress;Initial Catalog=dbemp;Integrated Security=True";
// Bulk Copy to SQL Server
SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
bulkInsert.DestinationTableName = "tbdata";
bulkInsert.WriteToServer(dr);
OleDbcon.Close();
Array.ForEach(Directory.GetFiles((Server.MapPath("~/Data/"))), File.Delete);
Label1.ForeColor = Color.Green;
Label1.Text = "successfully inserted";
FetchData();
newrow();
}
else
{
Label1.ForeColor = Color.Red;
Label1.Text = "Please select the File";
}
}
public void FetchData()
{
SqlConnection con = new SqlConnection(@"Data Source=vaio\sqlexpress;Initial Catalog=dbemp;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from tbdata", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
}
public void newrow()
{
SqlConnection con;
SqlDataAdapter dladpt;
DataSet dldst;
DataTable mydt;
con = new SqlConnection(@"Data Source=vaio\sqlexpress;Initial Catalog=dbemp;Integrated Security=True");
dladpt = new SqlDataAdapter("select * from tbdata", con);
dldst = new DataSet();
mydt = new DataTable();
dladpt.Fill(mydt);
DataColumn dcolColumn = new DataColumn("Link", typeof(string));
mydt.Columns.Add(dcolColumn);
DataRow drowItem;
foreach (DataRow row in mydt.Columns)
{
drowItem = mydt.NewRow();
drowItem["Link"] = "secret";
mydt.Rows.Add(drowItem);
}
GridView1.DataSource = mydt;
GridView1.DataBind();
}
}
|
|
|
|
|
Member 10578397 wrote: when import excel file to a table then automatic generate new add column to a
table (unique id )
ALTER the TABLE and ADD a COLUMN with an IDENTITY specification. It's done using SQL, not using datatables.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Greetings all.
I have 10 tabs with names tabPage01 to tabPage10. Inside those tabs there are textboxes named pathTXT01 to pathTXT10. Under each textbox there is a checkbox named changePath01 to changePath10. That check box is supposed to toggle .readonly for the textbox above it. So here is my function
private void changePath_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkTemp = sender as CheckBox;
string senderNumber = checkTemp.Name.Substring(checkTemp.Name.Length - 2, 2);
int tempMits = Convert.ToInt16(senderNumber);
string tempPathName = "pathTXT" + senderNumber;
TextBox papatrexas = ((TextBox)this.Controls[tempPathName]) as TextBox;
papatrexas.ReadOnly = !checkTemp.Checked;
}
Any help appreciated.
|
|
|
|
|
There are much, much better ways to do this.
Have a look at creating a UserControl[^]. This allows you to create a new control in your toolbox which can contain (and encapsulate) the text box and the check box - so the check box always knows which text box it is supposed to affect: there is only one as far as it is concerned!
Your code then becomes:
private void changePath_CheckedChanged(object sender, EventArgs e)
{
papatrexas.ReadOnly = !changePath.Checked;
} And everything becomes a lot easier to read and work with.
Usercontrols have constructors, properties, methods, events - everything a "normal" control does, so you can even create a UserControl which contains the whole of your tab page - and then just add one to each page in your TabControl instead of individual controls!
I use them a lot: they let me modularise the form a lot better and save a heck of a lot of time and confusion!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Hi,
This is about ListView class in c#. I need one customization for it. I need ListView with "word wrap" option for labels in the ListView header. When value in some column is short, but header label of the column is wider, then you are forced to make the width of the column unnecessary wider. It takes space. If there would be word wrap option, it could fix this issue for me. I didn't find any good sample of fixing this issue except ObjectListView which is excessive for me.
I hope there is a solution for me.
Thanks in advance,
Galym
|
|
|
|
|
If you're after a simple(ish) way, then just use WPF to create a ListView - you have full customisation of templates there. You can then just use an ElementHost to host it inside your Windows Forms application. There's no simple way in Windows Forms, because its implementation of ListView is just a thin wrapper of the Win32 version, so you have to drop down to effectively handling WM_OWNERDRAW .
|
|
|
|
|
|
Hello all
em searching for help in scanning file on virustotal using virustotal api.
i have gone through most sources google directed me to.
please help.
|
|
|
|
|
Member 10579673 wrote: please help. With what: you have not given us any idea where your problem lies?
|
|
|
|
|
Hi,
i need to access public static member of one class into another class.
please provide the help. Learning c#.
Ex:
class ABC
{
static int nEllipsecount = 0;
// in some function increment nEllipseCount;
};
// class xyz in another file
class ABC;
class xyz
{
if(ABC :: nEllipseCount >0)
{
//Process these statements;
}
};
i couldn't be able access static value into to another class.
is my approach wrong ? Please help me to resolve.
Thanks & Regards,
Royal
|
|
|
|
|
First, as you've shown it, nEllipsecount is NOT public.
In c# the default is private.
So, what you seem to want is:
class ABC
{
public static int nEllipsecount = 0;
}
class xyz
{
if (ABC.nEllipseCount >0)
{
}
}
If it isn't made public then you can't see it from xyz at all.
(Unless it is protected and you inherit from ABC .)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
Thanks alot Matt,
public static int nEllipsecount = 0;
In the above statement I'm declaring the static member in public only,
kindly tell me any other way i can declare as public.
Thanks & Regards,
Royal
|
|
|
|
|
You can't declare a public member/method/class etc, with anything other than the public keyword. C# requires explicit scope declaration if you're trying to do anything other than declare something as private, which is the default scope. What are you trying to achieve because using a public static is generally not a good idea?
|
|
|
|
|
Your code is hinting that you're working with C++ and not C#. Is this true??
|
|
|
|
|
Even in C++, which this is, you should not do that.
|
|
|
|
|
Can someone tell me how the moving tape/slideshow created in c# apps?It is often found on different websites, i.e. msn.arabia. Also tell the name of this feature in visual studio... Thanks
|
|
|
|
|
|
First let me pre-face, I am not looking for the LINQ answer. LINQ brings the entire document over the wire and then projects the document, which is worthless when trying to reduce network usage. Don't make me go to stack overflow!
Question:
How can I send a find query to MongoDB using the Official C# Mongo class library, and use a server-side projection? When I run
<br />
db.DBNAME.find(<br />
{_id:'401835_2014_05_01', <br />
Points: {<br />
$elemMatch: {<br />
ExtendedId:"xxxxxxx"<br />
} <br />
}<br />
},<br />
{ "Points.$":1}<br />
)<br />
from the command line (well ROBOMONGO) the world is a happy place and the projection works great. However, there seems to exist no method to call a server-side projection from the C# library????
note, I believe DB.eval can do it but db.eval is for ADMIN only and can lock the database so I am trying to avoid that option.
|
|
|
|
|
No idea if this makes any sense, but this SO answer[^] ( ) suggests that you can use the SetFields method[^] on your MongoCursor[^] to specify the server-side projection.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I will try it but I am not very optimistic. I am not attempting to restrict the fields but restrict the fields that match. For example: { "Points":1} would return the wrong document tree and the projection must be: { "Points.$":1}. The latter, unfortunately, isn't a field name.
|
|
|
|
|
Hi Guys
I would like to produce an internet cafe management system using C# and SQL, Has anyone done this before and had a successful system development?
Where would be a good starting point?
Thank You
|
|
|
|
|
Member 10920279 wrote: Has anyone done this before and had a successful system development? Yup.
Member 10920279 wrote: Where would be a good starting point? Google, keyword "kiosk mode".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Another way to do this query please
var topRatedProducts = (from product in _container.Products.Include("ProductReviews")
orderby product.ProductReviews.Average((x) => x.StarRate) descending
select product).Distinct((y) => y.ProductName);
return topRatedProducts.Take(iTopCount);
|
|
|
|