使用c#在asp.net中没有有效的文件名错误 [英] not a valid file name error in asp.net with c#
本文介绍了使用c#在asp.net中没有有效的文件名错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
public partial class frmcitymaster : System.Web.UI.Page
{
string str;
OleDbCommand cmd;
OleDbConnection con;
OleDbDataAdapter dtp;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Focus();
this.Title = "CITY FORM";
Classmysql.getconn();
con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:|DataDirectory|\jobdetail.mdb;Persist Security Info=True";
con.Open();
if (!IsPostBack)
{
str = "select * from statemaster";
cmd = new OleDbCommand(str, Classmysql.con);
dtp = new OleDbDataAdapter(cmd);
ds = new DataSet();
dtp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList1.DataSource = ds;
DropDownList1.DataValueField = "stateid";
DropDownList1.DataTextField = "statename";
DropDownList1.DataBind();
}
}
bindgrid();
}
protected void btnsave_Click(object sender, EventArgs e)
{
str = "select * from citymaster where cityname='" + txtCity.Text + "'";
cmd = new OleDbCommand(str,con);
dtp = new OleDbDataAdapter(cmd);
ds = new DataSet();
dtp.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
//for update record
str = "DELETE FROM citymaster where stateid=" +
DropDownList1.SelectedValue.ToString() + " and cityid=" + txtcityid.Text + "";
cmd = new OleDbCommand(str, Classmysql.con);
cmd.ExecuteNonQuery();
// maxno();
str = "insert into citymaster values(" + DropDownList1.SelectedValue.ToString() + "," + txtcityid.Text + ",'" + txtCity.Text + "')";
cmd= new OleDbCommand(str, con);
// cmd.Parameters.AddWithValue("@add", txtAdd.Text);
cmd.ExecuteNonQuery();
}
else {
lblmsg.Text = "this state name already exist select another";
txtCity.Text = "";
txtCity.Focus();
}
bindgrid();
}
int flag;
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
flag = 1;
ListItem l = DropDownList1.Items.FindByText(GridView1.SelectedRow.Cells[1].Text);
int index = DropDownList1.Items.IndexOf(l);
DropDownList1.SelectedIndex = index;
//txtstateid.Text = GridView1.SelectedRow.Cells[1].Text;
txtcityid.Text = GridView1.SelectedRow.Cells[2].Text;
txtCity.Text = GridView1.SelectedRow.Cells[3].Text;
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
ListItem l = DropDownList1.Items.FindByText(GridView1.Rows[e.RowIndex].Cells[1].Text);
int index = DropDownList1.Items.IndexOf(l);
DropDownList1.SelectedIndex = index;
str = "DELETE FROM citymaster where cityid=" +
GridView1.Rows[e.RowIndex].Cells[2].Text + " and stateid=" +
DropDownList1.SelectedValue.ToString();
cmd = new OleDbCommand(str, con);
cmd.ExecuteNonQuery();
GridView1.Rows[e.RowIndex].Visible = false;
}
public void bindgrid()
{
str = "select s.statename,c.cityid,c.cityname from "+
"citymaster c,statemaster s where s.stateid=c.stateid order by c.cityid desc";
cmd = new OleDbCommand(str, con);
dtp = new OleDbDataAdapter(cmd);
ds = new DataSet();
dtp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else { }
}
protected void btnNew_Click(object sender, EventArgs e)
{
// DropDownList1.SelectedIndex = 0;
txtCity.Text = "";
txtcityid.Text = "";
str = "select max(Cityid+1) from citymaster where stateid=" + DropDownList1.SelectedValue.ToString() + "";
cmd =new OleDbCommand(str,con);
dtp=new OleDbDataAdapter(cmd);
ds=new DataSet();
dtp.Fill(ds);
if (ds.Tables[0].Rows[0][0] == DBNull.Value)
{
txtcityid.Text = "1";
}
else
{
txtcityid.Text = ds.Tables[0].Rows[0][0].ToString();
}
bindgrid();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
}
}
推荐答案
似乎问题就在这一行。数据源的值不正确。
Seems problem is in this line. Data source has incorrect value.
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:|DataDirectory|\jobdetail.mdb;Persist Security Info=True";
试试这个
Try this
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataDirectory\jobdetail.mdb;Persist Security Info=True";
正如我昨天告诉你的:我的项目中的错误...... [ ^ ]
|文件名中不允许使用字符。
那么你为什么要使用它:
As I told you yesterday: error in my project....[^]
The "|" character is not allowed in file names.
So why are you trying to use it:
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:|DataDirectory|\jobdetail.mdb;Persist Security Info=True";
替换| DataDirectory |使用文件的实际路径,您的问题应该消失。
Replace the "|DataDirectory|" with the actual path to the file, and your problem should go away.
这篇关于使用c#在asp.net中没有有效的文件名错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文