|
How to change the name of the datagrid column thru programs?
For example.
in the table pmast, rcpno is the name of a field. But in the datagrid, I want to display the column heading as Receipt No.
The code is as follows :
Private Sub viewbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles viewbtn.Click
Dim strconv As New OleDb.OleDbConnection(ds)
disallbtn()
binddv = New OleDb.OleDbDataAdapter("select rcpno, rcpdt ,pname from pmast order by rcpno", strconv)
If Not oledv.Tables("pmast") Is Nothing Then
oledv.Tables("pmast").Clear()
End If
binddv.Fill(oledv, "pmast")
DataGridView1.DataSource = oledv.Tables("pmast")
DataGridView1.Show()
DataGridView1.Focus()
End Sub
|
|
|
|
|
Try this -
Dim myStyle As New DataGridTextBoxColumn
myStyle.MappingName = "Emp_name"
myStyle.HeaderText = "Employee Name"
|
|
|
|
|
Since your SQL code is in code use As clause in SQL with [receipt no] and modify your code to use Receipt no as the field name
|
|
|
|
|
Hi... Am new to .net here. Hope am posting the question under the right category... My requirement is as follows:
I have a gridview which is visible with an empty row on page load. It has four columns of which the first column is a text box item template. The rest 3 are bound fields. Now, when I enter a valid data in the text box(for eg, an employee ID)and hit the enter key, the rest of the fields must be bound to the grid. All four columns are available in a table in the back end. I have used a datatable and made the gridview datasource as the datatable. Am using a stored procedure to bind the data.. Using SQL Server 2008(.Net 3.5 framework). Kindly help... Im totally blank right now...
|
|
|
|
|
Following code is useful to you.
void dataGrid _EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dgr = (DataGridView)sender;
if (dgr.CurrentCell.ColumnIndex == 2)
{
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
}
}
}
void tb_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar)))
{
if (e.KeyChar == Keys.Enter)
{
e.Handled = true;
}
}
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
|
Hi sr159,
Please do not re-post the question.
You have already posted it here[^], and got resolution.
Please read guidelines[^] for better understanding of how to get answer and post question in this forum.
Hope you understand.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
hi sr159,
Why you have down voted me and removed your message?
Do not remove your message once you posted it, if it has
answers under it.
The question posted by sr159 is as follow
[Edit]
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
[/Edit]
Hope you understand.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
how to restore mysql dump file to database using C#
i am using following code but not working, if u know anyone please reply me
public void restore_data(string temple1)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <(4)", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
modified on Friday, July 16, 2010 3:18 AM
|
|
|
|
|
hi,
There isn't any option available to import mysql dump file directly to
sql server. Because the data exported by mysql as dump is not compatible
with sql server to restore at one go.
You need to use phpmyadmin or some other tool to export mysql database
(export as excel or some other format that is compatible in sql server),
instead of taking dump directly from command prompt.
And then try to restore it.
However, if you have to restore backup file of sql server into another
database (sql server to sql server) then it is absolutely possible in
C# using SQL SMO.
Find following link for the same.
http://www.geekpedia.com/tutorial180_Backup-and-restore-SQL-databases.html[^]
http://www.mssqltips.com/tip.asp?tip=1849[^]
And please use pre tag to format your code and mark your "Message Type" as "Question" not as "General".
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
we are using mysqlserver 2005 and sql yog for database management not sql server 2005
but the code which we are using is not working
|
|
|
|
|
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <(4)", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
I think the first issue is in the bracket you are using for 4th argument.
Instead of () you need to use {}.
Along with it you need to change one more line as follows.
ProcessStartInfo proc = new ProcessStartInfo(@"[FullPath]\mysql.exe");
because it will find mysql.exe file only if you put it in windows directory along
with supporting files.
And that's it. I have tried the same at my local machine with the code you have
provided and changes I have suggested, and it's running fine.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
i written and changed the like following code as you said but it is running the form but not updating to database. i think exe is not generating. previously exe cmd promt was coming for taking dump like that it is not coming
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void restore_data(string temple1)
{
StreamReader file = new treamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
|
|
|
|
|
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
|
|
|
|
|
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
|
|
|
|
|
Ok, I have found the problem and also resolution.
Consider following points in resolution.
1. Don't provide password when you are building arguments. You need to provide it later on
when you prompted for it.
2. you need to give filename as cmd.exe instead of mysql, because it will come under the
arguments.
For example, build your arguments as follows
string cmd = string.Format(@"C:\wamp\bin\mysql\mysql5.1.36\bin\mysql.exe -u {0} -p -h {1} {2} < {3}", "root", "localhost", "test123", @"C:\wamp\bin\mysql\mysql5.1.36\bin\wp.sql");
ProcessStartInfo proc = new ProcessStartInfo("cmd", @"/C " + cmd);
proc.UseShellExecute = false;
Process p = new Process();
p.StartInfo = proc;
p.Start();
p.WaitForExit();
See it I have not provided password. It should ask me for the password when I execute the process.
And that's it. It is now importing mysqldump file successfully.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
i changed as per instruction but again it is running but not saving to database and also not asking password and also we are not using wamp, we are using mysql 5.0. Please help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\cmd.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo("cmd", @"/C " + cmd);
//proc.RedirectStandardInput = true;
//proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
//Process p = Process.Start(proc);
string res;
//res = file.ReadToEnd();
//p.WaitForExit();
//file.Close();
Process p = new Process();
p.StartInfo = proc;
p.Start();
res = file.ReadToEnd();
p.WaitForExit();
}
}
}
|
|
|
|
|
i changed as per instruction but again it is running but not saving to database and also not asking password and also we are not using wamp, we are using mysql 5.0. Please help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\cmd.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo("cmd", @"/C " + cmd);
//proc.RedirectStandardInput = true;
//proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
//Process p = Process.Start(proc);
string res;
//res = file.ReadToEnd();
//p.WaitForExit();
//file.Close();
Process p = new Process();
p.StartInfo = proc;
p.Start();
res = file.ReadToEnd();
p.WaitForExit();
}
}
}
|
|
|
|
|
hi sr159,
You are not reading my answer. Again running wrong command.
Just read my answer carefully. I have supplied mysql instead of cmd command.
Instead of below line...
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\cmd.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
Just use the line...
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
And now execute the command. And try to edit your question not re-post or posting totally new question as reply by changing the message type.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
i changed cmd.exe to mysql.exe then also it is executing but not saving dump file to database using C#.
|
|
|
|
|
after running the processor which is taking the path is D:\the application folder name and not asking password.
|
|
|
|
|
problem solved now it is working thank you for all who replied to me
|
|
|
|
|
Thanks in advance.
how to convert a windows long path name to short pathname in VB.Net.
|
|
|
|
|
Find following code useful for the same.
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength
);
public static void Main()
{
StringBuilder shortPath = new StringBuilder(255);
GetShortPathName(@"D:\My Temp\ResourseProvider\sql.txt", shortPath, shortPath.Capacity);
Console.WriteLine(shortPath.ToString());
}
The code is in C#, however you can do the same with syntactical changes in vb.net.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I dunno who downvoted you, but I ran your code and it returned a correct answer. I got
E:\MYTEMP~1\RESOUR~1\sql.txt
However, it will fail if the path does not exist. Try the API on an existing path, and it will work.
I are Troll
|
|
|
|