|
This is not a ASP.Net forum
Put your queries related to ASP.Net in ASP.Net Forum
|
|
|
|
|
hi
This is my code in which i upload a excel file using file dialog box and store it in to the sql server as table name emp but problem is that when i run the program secound time all the values again store in same table
so my question is that is possible to create a table at run time in bata base NEED HELP or any logic regaring that.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace openfi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog FD = new OpenFileDialog();
FD.Filter = "Excel|*.xls";
if (FD.ShowDialog() == DialogResult.OK)
{
textBox1.Text = " " + FD.FileName;
}
string filename = textBox1.Text;
String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filename + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [sheet1$]", connection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = selectCommand;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
System.Data.DataTable dataTable = dataSet.Tables[0];
dataGridView1.DataSource = dataSet.Tables[0];
// textBox1.Text = "";
MessageBox.Show(dataGridView1.RowCount.ToString());
connection.Close();
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog FD = new OpenFileDialog();
FD.Filter = "Excel|*.xls";
if (FD.ShowDialog() == DialogResult.OK)
{
textBox2.Text = " " + FD.FileName;
}
string filename = textBox2.Text;
String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filename + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [sheet1$]", connection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = selectCommand;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
System.Data.DataTable dataTable = dataSet.Tables[0];
dataGridView2.DataSource = dataSet.Tables[0];
// textBox1.Text = "";
MessageBox.Show(dataGridView2.RowCount.ToString());
connection.Close();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button4_Click(object sender, EventArgs e)
{
string constr="data source=MYSERVER;initial catalog=mo;integrated security=SSPI";
// string constr = "Datasource=Myserver;Initialcatlog=mo;Integrated security=SSPI";
SqlConnection sqcon = new SqlConnection(constr);
SqlCommand scmd = new SqlCommand();
sqcon.Open();
int i = 1;
while (i < (dataGridView1.Rows.Count)-2)
{
string istr = "insert into emp(Personnel_Area,EE_Grp,Employee_Group,ES_Grp)values('" + Convert.ToString(dataGridView1.Rows[i].Cells[0].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[1].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[2].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[3].Value.ToString()) + "')";
MessageBox.Show(istr);
scmd.CommandText = istr;
scmd.Connection = sqcon;
int r;
r = scmd.ExecuteNonQuery();
if (r > 0)
// MessageBox.Show("Record Saved");
i++;
}
if (i > 1)
{
MessageBox.Show("Records saved");
}
}
}
}
|
|
|
|
|
Before doing your insert you should check first to see if the table exists, at which point you can specify another name for the table. I would dynamically set the table name in your code as a variable, and do a count on how many tables with that name already exist, and then create a new table based on that name and the count. This link may help you with the code on checking first to see if the table exists.
http://dotnetmonk.blogspot.com/2007/07/check-if-table-already-exists-in-sql.html[^]
hope this helps.
|
|
|
|
|
Something about this question just seems wrong to me. There should be one table in your database that contains all your "Customers" for example. Seems like a bad design to have "Customer_1_Jan_2009", and "Customers_2_Jan_2009", will you really want to query 'x' Customer tables for given date range as in the example provided?
Alternatively, if you have for example a Customer table in your database, and each customer might need some additional data for each individual customer, i would highly suggest storeing the additional information within an xml column if possible.
Or better yet figure out exactly what data you need to store, track, and maintain. You might have some specialized need to store data in this manor, but i simply can't think if a reason for it, seems like a bad design, and if you need to store daily inform for a given customer, then the date value should simply become a value withing the record.
|
|
|
|
|
hi dano2K3
i am working on the project in which i upload excel sheet from local disk and con vert it in to datagride after that all excel data stored in the database table for some further logic
when i run my program each time all same information in data gride store in same file that's why i want to create a table dynamically to avoide repitation in table need help
|
|
|
|
|
|
are you talking about notepad or something ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
rpopple wrote: In c# how do I controle the number of lines in an edit window
You must be more precise about what 'controle' means to you. Do you mean limit them in some way, or do you mean keep track of them, or what?
How can anyone help you with such an imprecise question?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,I am connected to an ftp server(cerberus ftp server, listening at port 21). I am having a trouble connecting to server while uploading a file,also need to know how to browse directory of a remote client(pc)
|
|
|
|
|
This is in vb but you should get the idea
^]
a programmer traped in a thugs body
|
|
|
|
|
I hope this link would be useful
FTP File in C#
contains a c# function to upload a file in c#
-----------------
logiclabz
|
|
|
|
|
thanks man its very helpful .
|
|
|
|
|
Hi.
I'm going to write a program for coloring and formatting C# Codes.
But I have an issue ?
When a word inserted by user, how I can find whether it's a class name ( in C# )
For example :
If a user has written Regex in the code editor, I wanna detect it as a class and dye it with a appropriate color.
Now , how can I realize whether a string is a class name in C# ?
Thanks in advance.
|
|
|
|
|
There's an article on CP somewhere that does something like intellisense in a rich text box. I can't find it right now but it shouldn;t be too hard to modify that code for what you want - if you can find the article.
[Edit] Found it here[^] [/Edit]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks, but it's a little complex project, and it takes me long time to find what I want.
|
|
|
|
|
10 minutes since I posted the link isn't 'long'
The theory is the same - keep a list of all loaded assemblies namespaces, properties, methods, fields, events, interfaces etc... and check against that list to set the color.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: The theory is the same - keep a list of all loaded assemblies namespaces, properties, methods, fields, events, interfaces etc... and check against that list to set the color.
Can I take all classes name in C# with Reflection ?
Sorry, if my question is wrong
|
|
|
|
|
Not sure in all honesty. If you can, you'll only be able to get at loaded/referenced assemblies unless you search through the dll's in the .net framework recursively - could be a long task that way.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi,
IMO you should collect the namespaces present in the referenced DLL files; and for each #using statement, investigate the namespace, collect all relevant names, and keep them in a fast collection, such as a HashSet or a Dictionary.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I have finished an application which uses .net. I created an installer and works fine but on some machines somethings don't behave, for example, I have a DataGridView with a button column and when pressed should open a form but on some machines it does not do anything. All machines have xp. I guess it could be .net framework.
How do I find what framework my app depends on? How do I find if it requires a certain fix like .net framework 1.1 hotfix?
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
If there is a missing depenency you should get an exception when your app tries to run the missing code. If you are swallowing exceptions then don't it is probably hiding the reason for your error.
If you can add logging to the area where the form should open then that may help.
|
|
|
|
|
I've built an InfoPath form that queries WMI data and displays it in the form so that we can submit the info to a SharePoint list.
I'm putting on the final touches and am having problems with one small section. When i query the RAM, i have it display the information into a repeating table. The problem is when i create the repeating table for some reason it duplicates the first row. I found an article on how to remove the first row (http://www.bizsupportonline.net/infopath2007/programmatically-delete-first-row-repeating-table-infopath.htm)
I use this same bit of code to remove the first row from another section and it works just fine, but for some reason when i do this very same thing it deletes the first 2 rows. I can't figure out why it works fine in one section but not in the other section, i copied and pasted the same bit of code so it should work the same. If someone could help me figure out what's going on here i'd appreciate it.
code sample:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Management;
using System.Net.NetworkInformation;
namespace Inventory_Rev1
{
public partial class FormCode
{
ManagementObjectSearcher searcherMemory =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
foreach (ManagementObject queryObj in searcherMemory.Get())
{
int counter = 1;
{
string slot = queryObj["DeviceLocator"].ToString();
string capacity = queryObj["Capacity"].ToString();
string speed = queryObj["Speed"].ToString();
XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:slot", ns)
.SetValue(slot);
xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:capacity", ns)
.SetValue(capacity);
xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:speed", ns)
.SetValue(speed);
counter++;
AddItemMemory(slot, capacity, speed);
DeleteFirstEmptyItemMemory();
}
}
}
private void AddItemMemory(string slot, string capacity, string speed)
{
XmlDocument doc = new XmlDocument();
XmlNode group = doc.CreateElement("Ram",
NamespaceManager.LookupNamespace("my"));
XmlNode field = doc.CreateElement("slot",
NamespaceManager.LookupNamespace("my"));
XmlNode node = group.AppendChild(field);
node.InnerText = slot;
field = doc.CreateElement("capacity",
NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = capacity;
field = doc.CreateElement("speed",
NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = speed;
doc.AppendChild(group);
MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:Memory",
NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
}
private void DeleteFirstEmptyItemMemory()
{
XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNavigator itemNav = domNav.SelectSingleNode(
"/my:myFields/my:Memory/my:Ram[1]",
NamespaceManager);
if (itemNav != null)
itemNav.DeleteSelf();
}
}
}
|
|
|
|
|
Hi all,
I've been searching high,low, and in between for a solution to my current problem & thought I'd post here to see if anyone here has tackled this one before.
I'm using VS2008, C#, & .Net3.5 SP1.
I have a USB based COM port attached to a GPS device, and I'm testing what happens when you unplug the USB cable while the SerialPort connection is open. The results are an unhandled exception & a program crash that occurs when the SerialPort.BaseStream is garbage collected, according to the callstack when the exception occurs..
The problem is discussed a bit @ this link[^], which includes this sample to reproduce:
using System;
using System.IO.Ports;
namespace SerialPortUsbCrash {
class Program {
static void Main(string[] args) {
SerialPort serialPort = null;
serialPort = new SerialPort("COM12", 19200, Parity.None, 8,
StopBits.One);
serialPort.Open();
Console.Write("Pull out the USB cable, and push return");
Console.ReadLine();
try {
serialPort.Close();
} catch (Exception ex) {
Console.WriteLine("Got exception closing SerialPort: " + ex);
}
Console.WriteLine("- THE END -");
Console.ReadLine();
}
}
I've tried a number of suggestions based on google searches, including app.config change, closing/disposing SerialPort on WM_DEVICECHANGE, GC.SuppressFinalization(serialPort.BaseStream) on device removal & others, but they don't resolve the issue.
Anybody here figure this one out?
Thanks.
|
|
|
|
|
I have no experience with SerialPort . However is it possible to
using (serialPort = new SerialPort("COM12", 19200, Parity.None, 8, StopBits.One))
{
serialPort.Open();
Console.Write("Pull out the USB cable, and push return");
Console.ReadLine();
try {
serialPort.Close();
} catch (Exception ex) {
Console.WriteLine("Got exception closing SerialPort: " + ex);
}
Console.WriteLine("- THE END -");
Console.ReadLine();
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for the reply!
If I use using(...), like you suggest, and the COM port is removed, what will happen is that the exception will occur sooner rather than later, as it'll happen not too long after the call to Dispose() occurs. Using using() just speeds that up a bit..
|
|
|
|
|